Skip to content

The Twelve Factors

The twelve factors are a set of rules for building applications that any environment can run unchanged: immutable, ephemeral, declared and automated. The canonical statement of each factor is quoted below from 12factor.net, alongside what it asks of an application in practice.

FactorCanonical ruleIn practice
CodebaseOne codebase tracked in revision control, many deploysOne repository per application. The same codebase produces every deploy of it; a second codebase means a second application.
DependenciesExplicitly declare and isolate dependenciesDeclare every dependency in a manifest and isolate it at runtime. Never rely on a package that happens to be installed system-wide.
ConfigStore config in the environmentAnything that differs between environments is separated from the code and read from the environment, not from a checked-in file.
Backing servicesTreat backing services as attached resourcesA database, broker or cache is reachable by a URL in config, and swapping a local instance for a managed one is a config change, not a code change.
Build, release, runStrictly separate build and run stagesBuild produces an artifact, release combines it with config, run executes it. A release is immutable and can be rolled back; code cannot be changed at runtime.
FactorCanonical ruleIn practice
ProcessesExecute the app as one or more stateless processesProcesses share nothing and hold no session state. Do not use sticky sessions; persist anything that must survive a request to a backing service.
Port bindingExport services via port bindingThe application binds its own port and serves HTTP itself, rather than depending on a webserver being injected into a runtime container around it.
ConcurrencyScale out via the process modelScale by running more processes of the right type, not only by making one process bigger.
DisposabilityMaximize robustness with fast startup and graceful shutdownFast startup so capacity can be added quickly, graceful shutdown on SIGTERM, and resilience to a process dying without warning.
Dev/prod parityKeep development, staging, and production as similar as possibleClose the gaps in time, personnel and tooling: dev = staging = prod, including using the same backing services in each.
LogsTreat logs as event streamsThe application writes an unbuffered event stream to stdout and never manages log files or rotation. The environment routes and stores it.
Admin processesRun admin/management tasks as one-off processesMigrations and one-off scripts run in an identical environment against the same release, as isolated processes, not by hand on a running instance.