The Twelve-Factor App is a methodology and set of best practices for building modern, scalable, and maintainable web applications. It was introduced by Adam Wiggins in 2011 and is designed to help developers create applications that are easy to deploy, scale, and maintain in a consistent and efficient manner.
The twelve factors are as follows:
- Codebase: One codebase tracked in revision control, many deploys. This factor emphasizes the importance of having a single codebase for an application that is version-controlled.
- Dependencies: Explicitly declare and isolate dependencies. The application should explicitly state its dependencies and manage them in a way that is isolated from the underlying system.
- Config: Store configuration in the environment. Configuration settings, such as API keys and database URLs, should be stored as environment variables rather than in the codebase.
- Backing Services: Treat backing services as attached resources. The application should be able to connect to various services (databases, queues, etc.) without code modification.
- Build, release, run: Strictly separate build and run stages. The process of building the application, releasing it, and running it should be distinct stages.
- Processes: Execute the app as one or more stateless processes. Applications should be designed to run as stateless processes, making them easier to scale and manage.
- Port Binding: Export services via port binding. The application should export services via a port binding, allowing it to be easily accessed by other applications.
- Concurrency: Scale out via the process model. Scalability should be achieved by running multiple, stateless processes rather than increasing the size of a single process.
- Disposability: Maximize robustness with fast startup and graceful shutdown. Applications should be designed to start up quickly and shut down gracefully, allowing for easy scaling and deployment.
- Dev/prod parity: Keep development, staging, and production as similar as possible. Developers should aim to minimize the differences between development, testing, and production environments to avoid issues caused by inconsistency.
- Logs: Treat logs as event streams. Applications should generate logs as event streams, making it easier to aggregate, analyze, and monitor them.
- Admin processes: Run admin/management tasks as one-off processes. Administrative or management tasks should be run as separate, one-off processes rather than being part of the application's core functionality.
By following the Twelve-Factor App methodology, developers can create applications that are more scalable, maintainable, and suitable for modern deployment practices such as containerization and cloud platforms.