The Twelve-Factor App
Twelve rules for apps that deploy cleanly, scale out and survive restarts, shown on one app from commit to production.
The Twelve-Factor App is a set of rules for building web apps and services that run well on cloud platforms. Engineers at Heroku wrote it in 2011 after watching thousands of apps deploy, and it still describes what platforms like Kubernetes expect from your code today.
An app that follows the twelve factors:
- deploys the same way everywhere, from a laptop to production;
- scales by running more copies, not by buying a bigger server;
- survives restarts, because no process holds anything it can't lose;
- lets you ship often, because development and production barely differ.
#One app, all twelve factors
Here is a single web app, from the laptop it's written on to the database it talks to. Pick a factor to see which parts of the app it's about, or press Play all to go through them in order.
1.Codebase
One app lives in one repository. Every environment runs a build of that same code, just at different commits.
#The factors, one page each
The numbers are the order the methodology lists them in. You don't have to read them in order, but the first five build on each other.
One repo per app, deployed many times.
2. DependenciesDeclare every package, and isolate them.
3. ConfigSettings that change per deploy live in the environment.
4. Backing servicesDatabases and queues are attached resources.
5. Build, release, runThree stages, kept strictly apart.
6. ProcessesStateless processes that share nothing.
7. Port bindingThe app serves HTTP on a port it is given.
8. ConcurrencyScale out by running more processes.
9. DisposabilityFast start, graceful stop.
10. Dev/prod parityKeep every environment alike.
11. LogsWrite events to stdout as a stream.
12. Admin processesRun one-off tasks like the app runs.
#Check yourself
The original text is at 12factor.net.