The Twelve-Factor App: A Blueprint for Portable Cloud Apps
The Twelve-Factor App is a blueprint for building portable, resilient cloud apps. It's used for microservices or apps on platforms like Kubernetes, ensuring they can be easily deployed and scaled. The footgun is treating it as dogma, not a guide.
WHY IT EXISTS To solve the "works on my machine" problem. Before these principles were codified, deploying apps was often a manual, error-prone process tied to specific servers and configurations. This created brittle systems that were difficult to scale, maintain, or move between environments like development and production.
THE MENTAL MODEL Think of your application as a self-contained, portable unit, like a shipping container. The Twelve-Factor methodology provides the design specs for that container, ensuring it can be moved, stacked (scaled), and managed by any standard platform (like Kubernetes) without needing to know what's inside. The goal is to minimize divergence between development and production.
HOW IT WORKS The methodology is a collection of twelve principles for building robust applications. Key ideas include: storing configuration in the environment, not in the code; treating backing services like databases as attached, swappable resources; executing the app as one or more stateless processes; and keeping development, staging, and production environments as similar as possible. These rules enforce a clean separation of concerns between the application and its environment.
WHEN TO USE IT Use these principles when building applications destined for the cloud, especially in a microservices architecture. It's ideal for projects that require continuous integration and deployment (CI/CD), horizontal scalability, and resilience against infrastructure changes. If your app will be managed by a Platform-as-a-Service (PaaS) or an orchestrator, following these factors is critical.
WHEN NOT TO USE IT For simple, monolithic applications running on a single, stable server, applying all twelve factors can be overkill. If your application has deep ties to a specific operating system or hardware (e.g., a desktop application or an embedded system), these cloud-centric principles may not be relevant or could add unnecessary complexity. It's a guide, not a mandate.
ONE CANONICAL EXAMPLE A classic example is managing an API key. A non-12-factor app might hardcode the key in a source file. A 12-factor app reads the key from an environment variable. This allows the same code to run in development (using a test key) and production (using a live key) without any code changes, just by setting the environment variable differently in each location.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.