Skip to main content

📄 12 Factor App

Notes from Kelsey's "12 Fractured Apps" post from 2015.

Key Points

  1. solve app issues at the app level; don't outsource it to config management or other hacks.
  2. config files should be optional: if a load fails fallback to sane defaults instead of trying & dying e.g. config files
  3. use config vars and override where needed, for config e.g. use if !="" and then grab it from os.Getenv()
  4. create if it doesn't exist i.e. a data dir
  5. use code to retry, with limits, database connections
  6. introducing a mechanism that needs an environment to support it, increases build size e.g. bash script brings in an alpine image
  7. adding a script now adds maintenance and another artifact that can "drift" and get out of sync i.e. the script
  8. keep config out of the container image
  9. don't require app starts in specific order, make each startup step not fatal when relying on each other.

The Twelve Factors

Source: "12factor.net"

I. Codebase

One codebase tracked in revision control, many deploys

II. Dependencies

Explicitly declare and isolate dependencies

III. Config

Store config in the environment

IV. Backing services

Treat backing services as attached resources

V. Build, release, run

Strictly separate build and run stages

VI. Processes

Execute the app as one or more stateless processes

VII. Port binding

Export services via port binding

VIII. Concurrency

Scale out via the process model

IX. Disposability

Maximize robustness with fast startup and graceful shutdown

X. Dev/prod parity

Keep development, staging, and production as similar as possible

XI. Logs

Treat logs as event streams

XII. Admin processes

Run admin/management tasks as one-off processes