📄 12 Factor App
Notes from Kelsey's "12 Fractured Apps" post from 2015.
Key Points
- solve app issues at the app level; don't outsource it to config management or other hacks.
- config files should be optional: if a load fails fallback to sane defaults instead of trying & dying e.g. config files
- use config vars and override where needed, for config e.g. use
if !=""
and then grab it fromos.Getenv()
- create if it doesn't exist i.e. a data dir
- use code to retry, with limits, database connections
- introducing a mechanism that needs an environment to support it, increases build size e.g. bash script brings in an alpine image
- adding a script now adds maintenance and another artifact that can "drift" and get out of sync i.e. the script
- keep config out of the container image
- 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