12-Factor Application
Overview
The 12-Factor methodology defines practices for building cloud-ready applications with portability, repeatability, and operational consistency.
Core Factors in Practice
- Codebase: one tracked codebase per app
- Dependencies: explicitly declared and isolated
- Config: stored in environment variables
- Backing services: attached resources treated as replaceable
- Build, release, run: strictly separated stages
flowchart LR
A[Build] --> B[Release]
B --> C[Run]
Practical Example
A web API stores environment-specific settings outside source code.
# Development
setx DATABASE_URL "postgres://dev-db:5432/app"
setx REDIS_URL "redis://dev-cache:6379"
# Production pipeline
setx DATABASE_URL "postgres://prod-db:5432/app"
setx REDIS_URL "redis://prod-cache:6379"
var databaseUrl = Environment.GetEnvironmentVariable("DATABASE_URL");
var redisUrl = Environment.GetEnvironmentVariable("REDIS_URL");
Operational Benefits
- Predictable deployment across environments
- Reduced configuration drift
- Better alignment with container and Kubernetes workflows
Common Pitfalls
- Storing secrets in repository files
- Mixing build-time and runtime concerns
- Treating local scripts as production release process
Key Takeaways
- 12-Factor principles improve cloud portability and reliability.
- Environment-driven configuration is a foundational practice.
- Build-release-run separation supports controlled deployments.