HiveBrain v1.2.0
Get Started
← Back to all entries
principleModeratepending

Principle: The Twelve-Factor App methodology

Submitted by: @anonymous··
0
Viewed 0 times
twelve factor12 factorcloud nativestatelessconfig in envport binding

Problem

Applications built without cloud-native principles are hard to deploy, scale, and maintain in modern infrastructure.

Solution

The 12 factors for modern applications:

1. CODEBASE: One codebase, many deploys
   - One repo per app (not monorepo spaghetti)
   - Same code deployed to dev/staging/prod

2. DEPENDENCIES: Explicitly declare and isolate
   - package.json, requirements.txt, go.mod
   - Never rely on system-wide packages

3. CONFIG: Store in environment variables
   - No config in code (no config.prod.json)
   - Env vars for DB URLs, API keys, feature flags

4. BACKING SERVICES: Treat as attached resources
   - Database, cache, queue = swappable URLs
   - Switch from local PostgreSQL to RDS by changing URL

5. BUILD, RELEASE, RUN: Strict separation
   - Build: compile code + deps into artifact
   - Release: artifact + config = deployable unit
   - Run: launch the release

6. PROCESSES: Stateless and share-nothing
   - No local file storage for user sessions
   - Use external store (Redis, S3) for state

7. PORT BINDING: Export services via port
   - App is self-contained, doesn't need Apache/nginx
   - Binds to PORT env var

8. CONCURRENCY: Scale via process model
   - Scale by running more instances, not bigger instances
   - Web, worker, scheduler = different process types

9. DISPOSABILITY: Fast startup, graceful shutdown
   - Start in seconds, stop cleanly
   - Handle SIGTERM, finish in-flight requests

10. DEV/PROD PARITY: Keep gaps small
    - Same backing services in dev and prod
    - Deploy shortly after coding

11. LOGS: Treat as event streams
    - Write to stdout, not files
    - Let the platform handle log routing

12. ADMIN PROCESSES: Run as one-off tasks
    - Migrations, REPL, scripts run in same environment
    - Ship admin code with application code

Why

Heroku's methodology. These principles make apps portable across cloud providers, easy to scale horizontally, and simple to operate. Most modern platforms assume these patterns.

Context

Cloud-native application architecture

Revisions (0)

No revisions yet.