The Twelve-Factor App
Understanding the Twelve-Factor App
In the current technological landscape, software is predominantly delivered as a service—commonly referred to as web apps or Software-as-a-Service (SaaS).
The Methodology
The Twelve-Factor App is a strategic framework designed for building SaaS applications. Its primary objectives are to ensure that software is:
- Automated via Declarative Formats: This reduces the overhead and associated with onboarding new engineers.
- OS-Agnostic: By maintaining a strict contract with the underlying operating system, the app achieves maximum portability across different environments.
- Cloud-Ready: Designed for modern cloud platforms, removing the necessity for
traditional server managementand dedicated systems administration. - Consistent Across Environments: By minimizing the gap between development and production, teams can achieve continuous deployment and higher agility.
- Scalable: The architecture allows for growth without requiring fundamental changes to the codebase or tooling.
Summary of Goals and Benefits
| Goal | Primary Benefit |
|---|---|
| Declarative Setup | Onboarding Time |
| Clean OS Contract | Portability |
| Cloud Native | SysAdmin Overhead |
| Dev/Prod Parity | Deployment Agility |
| Seamless Scaling | Architectural Friction |
Context and Origins
The authors of this methodology drew from their direct experience developing hundreds of applications and their indirect observation of hundreds of thousands of apps through the Heroku platform.
This framework is a synthesis of real-world observations of SaaS applications in production. It aims to triangulate the "ideal" path for development, focusing on how apps grow organically, how developers collaborate, and how to prevent the inevitable decay known as software erosion.
The goal is to establish a shared technical vocabulary to describe systemic development problems and provide conceptual blueprints for their solutions. The structural approach is heavily influenced by the work of Martin Fowler, specifically his texts on Refactoring and Patterns of Enterprise Application Architecture.
Core Principles (Partial List)
The methodology is language-agnostic and works regardless of the backing services (e.g., Redis, PostgreSQL, RabbitMQ) utilized.
- I. Codebase: A single repository tracked in version control (e.g.,
git) that maps to many deployment instances. - II. Dependencies: Isolate and explicitly define all dependencies; do not rely on implicit system-wide packages.
- III. Backing Services: Treat all external resources (databases, caches) as attached resources.
- IV. Build, Release, Run: Maintain a strict separation between the build stage, the release stage, and the execution stage.
- V. Processes: The application must run as one or more stateless processes.
- VI. Disposability: Ensure fast startup and graceful shutdowns to maximize robustness.
- VII. Dev/Prod Parity: Keep the development, staging, and production environments as identical as possible.
- VIII. Admin Processes: Execute administrative or management tasks as one-off processes.
Example: Declarative Dependency Management
Instead of manually installing packages on a server, a twelve-factor app uses a manifest:
# Example dependency declaration
dependencies:
- name: postgres-client
version: 13.0
- name: redis-server
version: 6.2