Stage 3 · Build
Production-Ready Services
12-Factor Services
Apply 12-factor principles for config, logs, disposability, backing services, and build-release-run.
What Is 12-Factor
The 12-Factor App is a methodology for building modern, scalable SaaS applications. It covers code organization, dependencies, configuration, logs, and deployment. Following these principles makes your services portable and maintainable.
Codebase
One codebase tracked in version control, many deploys. Never mix code for multiple services in one repository. Each service has its own repo. Shared code is extracted into libraries.
Dependencies
Config
Store configuration in environment variables. Never in code. This includes database URLs, API keys, feature flags, and port numbers. Different environments get different configs without code changes.
Backing Services
Treat backing services (databases, caches, queues) as attached resources. Connect via URL. If the database moves from local to AWS RDS, change the URL, not the code.
Disposability
Services must be disposable — fast to start up and graceful to shut down. This enables rapid scaling, deployments, and recovery from crashes.
- Fast startup: Bind to ports and connect to backing services in under 1 second.
- Graceful shutdown: Handle SIGTERM, drain connections, release resources.
- Robust against sudden death: Use process managers and health checks.
- Idempotent operations: Safe to restart mid-request without data corruption.
Separate build (compile binary), release (attach config), and run (start process). This ensures the same binary runs in every environment. Config is attached at runtime, not compile time.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.