The Twelve-Factor App methodology, published by Heroku engineers in 2012, defines twelve principles for building software-as-a-service applications that are portable, scalable, and maintainable. The factors address the full software delivery lifecycle — from codebase management through configuration, dependency isolation, process model, and disposability. A twelve-factor app can be deployed to any cloud without modification, scales horizontally by adding process instances, and has no divergence between development and production environments. These principles have become the baseline expectation for cloud-native architecture and underpin Kubernetes pod design, container image best practices, and GitOps workflows.

Key Points

  • Factor I (Codebase): one repo per app tracked in version control; multiple deploys (dev, staging, prod) from the same codebase — never one repo per environment.
  • Factor III (Config): store all config that varies between deployments in environment variables — never hardcode credentials, service URLs, or feature flags in code or config files committed to source control.
  • Factor V (Build/Release/Run): strictly separate build (compile + bundle), release (build + config = immutable artifact), and run (execute release) — enables atomic rollback by deploying a previous release.
  • Factor VI (Processes): execute as one or more stateless processes; share-nothing between instances; external state (sessions, queues, files) lives in a backing service, not in process memory.
  • Factor VII (Port Binding): export services via port binding (an HTTP server embedded in the app, not deployed into an app server) — the app is self-contained; routing is the platform's job.
  • Factor IX (Disposability): fast startup (seconds, not minutes) and graceful shutdown — enables elastic scaling, deployment without downtime, and crash-safe operation with automatic restart.
  • Factor X (Dev/Prod Parity): minimize time, personnel, and tool gaps between development and production environments — Docker Compose locally mirrors Kubernetes in prod to prevent "works on my machine" failures.
  • Factor XI (Logs): treat logs as event streams to stdout/stderr — never manage log files in the app; let the execution environment (Kubernetes, Heroku) route log streams to Splunk, Datadog, or CloudWatch.
FactorNamePrincipleAnti-Pattern to Avoid
ICodebaseOne codebase tracked in VCS, many deploysSeparate repos per environment; copy-paste codebases
IIDependenciesExplicitly declare and isolate dependenciesRelying on system-wide installed packages (no package.json/requirements.txt)
IIIConfigStore config in environment variablesConfig files committed to git; hardcoded credentials
IVBacking ServicesTreat backing services as attached resourcesDistinguishing local vs. remote DB in code; hardcoded service URLs
VBuild/Release/RunStrictly separate build and run stagesSSH-ing into production to make changes; mutable deployments
VIProcessesExecute as stateless, share-nothing processesSticky sessions; in-memory session state; local file system state
VIIPort BindingExport services via port bindingDeploying to external app servers (Tomcat war files); managed app containers
VIIIConcurrencyScale out via the process modelThreads as primary concurrency unit; scaling by making one process bigger
IXDisposabilityFast startup, graceful shutdownLong startup time; not handling SIGTERM gracefully; in-flight request dropping
XDev/Prod ParityKeep dev, staging, prod as similar as possibleSQLite in dev, PostgreSQL in prod; different OS between local and prod
XILogsTreat logs as event streamsWriting log files to disk; log rotation inside the app; parsing structured logs from files
XIIAdmin ProcessesRun admin tasks as one-off processesRunning migrations inside the app startup; SSH ad-hoc scripts

Real-World Example

Heroku's entire platform is an implementation of the Twelve-Factor methodology — the dyno model (Factor VI, VIII), config vars (Factor III), add-ons as attached resources (Factor IV), and the release system (Factor V) directly implement these principles. The methodology's influence is visible in every Kubernetes deployment: container images are immutable releases, environment variables carry config, and health checks enforce disposability.