The Twelve Factors
lastmod 2019-11-08created 2019-11-084 edits
Introduction
As delivering software as a service has recently become common, it has come to be called a web app or SaaS (Software As A Service). The Twelve-Factor app is a methodology for building SaaS apps with the following characteristics.
- Systematizes procedures (declarative) for setup automation, minimizing the time and cost for new developers to join the project.
- Clarifies the parts that depend on the OS and maximizes portability between execution environments.
- Suitable for deployment on modern cloud platforms, removing the need to manage servers and systems.
- Enables continuous deployment to minimize the gap between development and production environments and maximize agility.
- Can scale up without significant changes to tooling, architecture, or development practices.
The Twelve-Factor methodology can be applied to apps written in any programming language and used in various combinations with backing services (databases, queues, memory caches, etc.).
Background
The contributors to this document have been directly involved in the development and deployment of hundreds of apps, and indirectly observed the development, operation, and scaling of a vast number of apps through the Heroku platform.
This document synthesizes experience and observations from a wide variety of SaaS apps in actual use. It seeks an ideal approach to app development, focusing in particular on how apps grow organically over time, collaboration between developers working on an app's codebase, and how to reduce the maintenance cost of software that erodes over time.
This document was written to raise awareness of some systemic problems we have encountered in modern application development, to provide a shared vocabulary for discussing these problems, and to offer broad conceptual solutions to these problems along with accompanying terminology. The format is inspired by Martin Fowler's books Patterns of Enterprise Application Architecture and Refactoring.
Codebase
One codebase tracked in version control, many deploys
Dependencies
Explicitly declare and isolate dependencies
Config
Store config in the environment
Backing services
Treat backing services as attached resources
Build, release, run
Strictly separate build and run stages
Processes
Execute the application as one or more stateless processes
Port binding
Export services via port binding
Concurrency
Scale out via the process model
Disposability
Maximize robustness with fast startup and graceful shutdown
Dev/prod parity
Keep development, staging, and production as similar as possible
Logs
Treat logs as event streams
Admin processes
Run admin/maintenance tasks as one-off processes