12-Factor App Methodology
A set of twelve principles for building modern, scalable, maintainable software-as-a-service applications.
Description
The 12-Factor App methodology is a set of principles for building cloud-native applications that are portable, scalable, and maintainable. Originally articulated by Heroku co-founder Adam Wiggins, these factors address codebase management, dependency declaration, configuration externalization, backing service abstraction, build/release/run separation, stateless processes, port binding, concurrency via process model, disposability, dev/prod parity, log streaming, and admin process management.
In practice, adhering to these factors means using a single codebase tracked in version control, explicitly declaring all dependencies (no implicit system-level dependencies), storing config in the environment, treating databases, caches, and message queues as attached resources swappable via URL changes, building immutable release artifacts, running stateless processes that store session data in external stores, and scaling horizontally by adding process instances rather than scaling vertically.
The methodology promotes applications that start up fast and shut down gracefully (disposability), maintain minimal divergence between development and production environments (dev/prod parity), treat logs as unbuffered event streams routed to external aggregators, and run administrative tasks as one-off processes using the same codebase and config. While originally targeted at PaaS deployments, these principles remain foundational for containerized and serverless architectures.
Prompt Snippet
Architect the application following 12-Factor principles: single Git repo with no shared code via copy-paste, all dependencies in package.json with exact lockfile, config via environment variables validated at boot, backing services (Postgres, Redis, S3) addressed by URL and swappable per environment, immutable Docker image built once and promoted through stages, stateless request handling with sessions in Redis, horizontal scaling via process replication behind a load balancer, graceful shutdown on SIGTERM within a 30-second timeout, and logs emitted as structured JSON to stdout.
Tags
Related Terms
Environment Variable Management
Externalize application configuration into environment variables to separate config from code across environments.
Docker Containerization
Package applications and their dependencies into isolated, portable containers using Docker.
Graceful Shutdown
Handle process termination signals to finish in-flight requests and close resources cleanly before exiting.
Application Logging (Structured)
Emit application logs as structured, machine-parseable records with consistent fields for efficient searching and analysis.
Auto-Scaling
Automatically adjust the number of running application instances based on real-time demand metrics.