12 Factor App


What is a 12 Factor App?

The 12 Factor App is a methodology to develop SaaS apps.

A 12 Factor App

The 12 Factors of a 12 Factor App

1. Codebase

One codebase tracked in revision control, many deploys

2. Dependencies

Explicitly declare and isolate dependencies

=> In Rails: Gemfile as manifest and bundle exec for dependency isolation

3. Config

Store config in the environment

Here, config are defined to contain everything that might vary between deploys.
So i.e. Routes do not count.

4. Backing Services

Treat backing services as attached resources

A backing service is any service the app consumes over the network as part of its normal operation. (Datastores, messaging/querying systems, SMTP services and caching systems)

5. Build, release, run

Strictly separate build and run stages

Build stage: converts the code repo into an executable bundle = the build
Release stage: the build is combined with the environments' config. The resulting release is ready for immediate execution.
Run stage: aka runtime runs the app in the execution environment.

6. Processes

Execute the app as one or more stateless processes

7. Port binding

Export services via port binding

8. Concurrency

Scale out via the process model

9. Disposability

Maximize robustness with fast startup and graceful shutdown

10. Dev/prod parity

Keep development, staging, and production as similar as possible

Traditional app Twelve-factor app
Time between deploys Weeks Hours
Code authors vs code deployers Different people Same people
Dev vs production environments Divergent As similar as possible
This also means that the same backing services (like DBs) should be used in all the environments (no SQLite for local development)

11. Logs

Treat logs as event streams

12. Admin Processes

Run admin/management tasks as one-off processes