01.12.2016 Views

Beyond the Twelve-Factor App

beyond_the_12-factor_app_pivotal

beyond_the_12-factor_app_pivotal

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

can create and consume transient state in <strong>the</strong> middle of handling a<br />

request or processing a transaction, but that data should all be gone<br />

by <strong>the</strong> time <strong>the</strong> client has been given a response.<br />

To put it as simply as possible, all long-lasting state must be external<br />

to <strong>the</strong> application, provided by backing services. So <strong>the</strong> concept isn’t<br />

that state cannot exist; it is that it cannot be maintained within your<br />

application.<br />

As an example, a microservice that exposes functionality for user<br />

management must be stateless, so <strong>the</strong> list of all users is maintained<br />

in a backing service (an Oracle or MongoDB database, for instance).<br />

For obvious reasons, it would make no sense for a database to be<br />

stateless.<br />

The Share-Nothing Pattern<br />

Processes often communicate with each o<strong>the</strong>r by sharing common<br />

resources. Even without considering <strong>the</strong> move to <strong>the</strong> cloud, <strong>the</strong>re<br />

are a number of benefits to be gained from adopting <strong>the</strong> sharenothing<br />

pattern.<br />

Firstly, anything shared among processes is a liability that makes all<br />

of those processes more brittle. In many high-availability patterns,<br />

processes will share data through a wide variety of techniques to<br />

elect cluster leaders, to decide on whe<strong>the</strong>r a process is a primary or<br />

backup, and so on.<br />

All of <strong>the</strong>se options need to be avoided when running in <strong>the</strong> cloud.<br />

Your processes can vanish at a moment’s notice with no warning,<br />

and that’s a good thing. Processes come and go, scale horizontally<br />

and vertically, and are highly disposable. This means that anything<br />

shared among processes could also vanish, potentially causing a cascading<br />

failure.<br />

It should go without saying, but <strong>the</strong> filesystem is not a backing service.<br />

This means that you cannot consider files a means by which<br />

applications can share data. Disks in <strong>the</strong> cloud are ephemeral and, in<br />

some cases, even read-only.<br />

If processes need to share data, like session state for a group of processes<br />

forming a web farm, <strong>the</strong>n that session state should be externalized<br />

and made available through a true backing service.<br />

40 | Chapter 12: Stateless Processes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!