The 12-Factor App

2 min read

The 12-Factor App is a set of best practices for building modern, scalable, and maintainable cloud-native applications. It was introduced by Heroku to help developers build software that is portable, resilient, and easy to deploy. Here’s a quick overview of the 12 factors:
1. Codebase
- One codebase per application, tracked in version control (e.g., Git), with multiple deployments (dev, staging, prod).
2. Dependencies
- Explicitly declare dependencies in a package manager (e.g.,
requirements.txt
for Python,package.json
for Node.js).
3. Config
- Store configuration (e.g., database URLs, API keys) in environment variables, not in code.
4. Backing Services
- Treat databases, caches, and message queues as attached resources that can be swapped easily.
5. Build, Release, Run
- Separate the build (compiling code), release (config + build), and run (execution) stages.
6. Processes
- The app should be stateless, meaning it doesn’t store session data on the server (use a database or cache instead).
7. Port Binding
- The app should be self-contained and expose services via a port (e.g., using
localhost:5000
instead of a hardcoded address).
8. Concurrency
- Scale out by running multiple stateless processes instead of large monolithic instances.
9. Disposability
- Apps should be resilient and able to start/stop quickly to handle failures and deployments efficiently.
10. Dev/Prod Parity
- Keep development, staging, and production environments as similar as possible to reduce issues when deploying.
11. Logs
- Treat logs as event streams and send them to a logging system like ELK Stack, Splunk, or Fluentd instead of storing them in files.
12. Admin Processes
- Run one-time admin tasks (e.g., database migrations, cron jobs) separately from the main application processes.
Why is the 12-Factor App Important?
✅ Cloud-native: Designed for microservices and containerized environments like Kubernetes
✅ Scalable: Easily scales with demand
✅ Portable: Can be deployed on different platforms (AWS, Azure, GCP, etc.)
✅ Maintainable: Reduces tech debt and makes debugging easier
0
Subscribe to my newsletter
Read articles from Aravind Manoharan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
