The Twelve-Factor App

Twelve practices for building services that deploy, scale and run cleanly in the cloud.

The Twelve-Factor App methodology, published by engineers at Heroku, describes how to build software-as-a-service applications that are portable, scalable and easy to deploy continuously. More than a decade later, it still describes what makes a service a good citizen on containers, Kubernetes and serverless platforms.

Most of the factors are now built into modern platforms, which makes them easy to follow, and easy to break if you are not aware of them.

Factors 1–4: code and configuration

1. Codebase
One codebase in version control, deployed to many environments.
2. Dependencies
Declare and isolate all dependencies explicitly; never rely on what happens to be installed.
3. Config
Store configuration in the environment, not in code, so the same build runs everywhere.
4. Backing services
Treat databases, queues and caches as attached resources, swappable through configuration.

Factors 5–8: build and run

5. Build, release, run
Separate stages: build an artifact once, combine it with config to release, then run it.
6. Processes
Run as stateless processes; keep state in backing services.
7. Port binding
Export services by binding to a port, self-contained.
8. Concurrency
Scale out by running more processes, not by making one process bigger.

Factors 9–12: operations

9. Disposability
Start fast and shut down gracefully, so instances can come and go freely.
10. Dev/prod parity
Keep development, staging and production as similar as possible.
11. Logs
Treat logs as event streams written to standard output, collected by the platform.
12. Admin processes
Run one-off admin tasks, such as migrations, as separate processes with the same code and config.

Twelve factors on modern platforms

Containers make dependency isolation and port binding natural; Kubernetes and serverless platforms expect statelessness and disposability; CI/CD pipelines implement build, release, run. Secrets belong in a secret manager injected as environment variables rather than in plain config files.

Commonly added practices include API-first design, telemetry with metrics and traces, and authentication built in from the start.

Where teams slip

The most common breaks are configuration baked into images, local file storage that disappears when an instance restarts, long startup times that slow scaling, and development environments that differ so much from production that bugs only appear after release.

A quick self-check

Ask five questions of any service. Can the same artifact run in every environment with only configuration changing? Can any instance be killed without losing data? Does a new instance start in seconds? Do logs go to standard output? Are all dependencies declared? A "no" to any of these is a good place to start improving.

Beyond the twelve

Teams often add a few factors for modern systems: design APIs first, build in telemetry from the start, and handle authentication and authorisation as a core concern. These extend the original methodology without changing its spirit: services that are easy to deploy, scale and operate.

How to put it into practice

  1. Check one service against all twelve factors and list the gaps.
  2. Move configuration and secrets out of code and images.
  3. Make services stateless; move sessions and files to backing services.
  4. Build once in CI and promote the same artifact through environments.
  5. Write logs to standard output in a structured format.
  6. Use containers or managed environments to keep dev and prod similar.

Common mistakes

  • Different builds for each environment.
  • Storing uploaded files on the local disk of an instance.
  • Secrets committed to repositories or baked into images.
  • Slow startup that makes autoscaling ineffective.

How to measure progress

  • Share of services meeting all twelve factors.
  • Time for a new instance to start and serve traffic.
  • Incidents caused by environment differences.
  • Secrets found in code or images (aim for zero).

Go further