What is Twelve-Factor App?
Is an architectural style for building RESTful applications that fits well with cloud and microservice philosophies.
Name | Description | |
---|---|---|
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 |
For our purposes we will focus on III Config, VII Port Binding, IX Disposability and XI Logs.
Config
The twelve-factor app stores config in environment variables (often shortened to env vars or env). Env vars are easy to change between deploys without changing any code … https://12factor.net/config
This factor says that we will store the configuration in environment variables to be able to set them for whatever envrionment is necessary. In Golang, this is fairly trivial with the help of Kelsey Hightower’s envconfig
library. This library
Port Binding
Simple again, now that we have the
Disposability
We want to gracefully shutdown as we might be yanked at anytime
Logs
logs to stdout to be able to be picked up