Codebase: Maintain a single codebase in a version control system (e.g., Git) and use it for multiple deployments across different environments (development, staging, production).
Dependencies: Explicitly declare and isolate dependencies. Avoid relying on system-wide libraries and ensure that all required dependencies are defined in the application's configuration.
Config: Store configuration settings (e.g., database credentials, API keys) in environment variables or configuration files, separate from the codebase. This allows for easy configuration changes without code modifications.
Backing Services: Treat backing services (databases, message queues, caches) as attached resources. The connection information and credentials for these services should be configurable externally, not hard-coded.
Build, Release, Run: Separate the build, release, and run stages of deployment. This means creating distinct steps for building the application, releasing it with its configuration, and running it in the desired environment.
Processes: Run the application as one or more stateless processes that share nothing. Avoid storing session state or data on the application server. Use external data stores or services for stateful operations.
Port Binding: Export services via a well-defined port binding. The application should be self-contained and listen on a specific port, making it easy to expose externally.
Concurrency: Scale the application by adding more process instances (horizontal scaling) rather than relying on vertical scaling. Each process instance should be stateless and independently scalable.
Disposability: Design the application for quick and graceful shutdown. Use stateless processes and handle the termination of processes gracefully to ensure a smooth scaling and deployment experience.
Dev/Prod Parity: Keep development, staging, and production environments as similar as possible. Use the same dependencies, configuration, and environment as much as possible to minimize deployment-related issues.
Logs: Treat logs as event streams. Log output should be treated as a continuous stream of data that can be easily collected, aggregated, and analyzed. Avoid writing to local files or relying on non-streaming log mechanisms.
Admin Processes: Run administrative tasks as one-off processes. Use a separate code path for running one-time or periodic administrative tasks (e.g., database migrations) instead of adding them to the application code.
The "12 Factor App" methodology is not limited to a specific programming language or framework but provides general guidelines for building applications that are highly portable, maintainable, and scalable. Adopting these principles can help developers and teams build resilient and cloud-ready applications that are well-suited for modern infrastructure and deployment practices.