Twelve-Factor Apps and Cloud-Native Habits
Follow the conventions that make a service easy to deploy, scale and operate on any modern platform.
Intermediate · about 2 hours · difficulty 2/5
Learn first: Managing Secrets and Configuration, Containers with Docker
The Twelve-Factor App is a short methodology, written by Heroku engineers, describing how to build services that run cleanly on cloud platforms. Most modern deployment tools (containers, Kubernetes, PaaS) assume you follow it.
The factors that matter most day to day
- Codebase: one repo per app, many deploys (dev, staging, prod) from it.
- Dependencies: declared explicitly in a manifest and lockfile; nothing assumed to be preinstalled.
- Config in the environment: URLs, credentials and flags come from environment variables, never from code. The same build runs in every environment.
- Backing services (databases, queues, email) are attached resources swapped by changing config.
- Build, release, run are separate stages; a release is an immutable build plus config.
- Processes are stateless and share nothing; state lives in backing services.
- Port binding: the app is self-contained and exposes HTTP on a port.
- Concurrency: scale out by running more processes.
- Disposability: fast startup and graceful shutdown on SIGTERM.
- Dev/prod parity: keep environments similar (containers help).
- Logs as event streams to stdout; the platform collects them.
- Admin processes (migrations, one-off scripts) run as one-off processes against the same release.
Beyond the original twelve
Modern teams add: health check endpoints, structured logs, metrics and traces, secure-by-default dependencies, and API-first design.
Pitfalls
- Config files per environment committed to the repo with secrets inside.
- Writing uploads or sessions to local disk, which breaks the moment you scale to two instances.
You are ready to move on when you can audit your own service against each factor and fix at least the config, logs, statelessness and disposability ones.
Key concepts
- Config in environment variables
- Stateless processes
- Build, release, run
- Disposability and graceful shutdown
- Logs as event streams
- Dev/prod parity
- Admin processes
Mini project
Audit one of your services against all twelve factors in a checklist, then fix the three biggest gaps and note what changed.
Check yourself
Why does storing user sessions in process memory violate twelve-factor principles, and what breaks in practice?
Free resources
- The Twelve-Factor App (12factor.net)
- Cloud Native Computing Foundation glossary (CNCF)