Skip to content

1. 🏭 The 12 Factor App

In the modern era, software is created as web apps or software-as-a-service. The 12 factor app is a methodology for building software-as-a-service apps that:

Key Principles

  • Use declarative formats for setup automation
  • Have a clean contract with the underlying OS
  • Are suitable for deployment on modern cloud platforms
  • Minimize divergence between development and production
  • Can scale up without significant changes

1.1. 1⃣ I. Codebase

One codebase tracked in revision control, many deploys

  • Always tracked with version control system (e.g., Git, Mercurial, Subversion)
  • One-to-one correlation between codebase and app
  • Multiple codebases = distributed system
  • Shared code should be factored into libraries

Codebase and Deploys

1.2. 2⃣ II. Dependencies

Explicitly declare and isolate dependencies

  • Never rely on implicit system-wide packages
  • Declare all dependencies via a dependency declaration manifest
  • Use a dependency isolation tool during execution

💡 Example in Python: - Pip for declaration - Virtualenv for isolation

1.3. 3⃣ III. Config

Store config in the environment

  • Config includes: database handles, credentials, per-deploy values
  • Strict separation of config from code
  • Store config in environment variables

❌ Avoid: - Constants in code - Config files not in revision control - Grouped "environments" (e.g., development, test, production)

1.4. 4⃣ IV. Backing Services

Treat backing services as attached resources

  • Examples: datastores, messaging systems, SMTP services, caching systems
  • No distinction between local and third-party services
  • Access via URL or credentials stored in config

1.5. 5⃣ V. Build, release, run

Strictly separate build and run stages

  1. Build stage: Fetch dependencies, compile binaries and assets
  2. Release stage: Combine build with config
  3. Run stage: Execute app in the environment

Release Process

1.6. 6⃣ VI. Processes

Execute the app as one or more stateless processes

  • Processes are stateless and share-nothing
  • Persist data in stateful backing services (e.g., databases)

1.7. 7⃣ VII. Port binding

Export services via port binding

  • App is completely self-contained
  • Exports HTTP as a service by binding to a port

1.8. 8⃣ VIII. Concurrency

Scale out via the process model

  • Processes are a first-class citizen
  • Enable horizontal scaling
  • Rely on the OS's process manager

1.9. 9⃣ IX. Disposability

Maximize robustness with fast startup and graceful shutdown

1.10. 🔟 X. Dev/prod parity

1.11. 1⃣1⃣ XI. Logs

1.12. 1⃣2⃣ XII. Admin processes

2. 📚 Resources