What is the Twelve-Factor App principle about configuration?
BeginnerConceptDatabase connections in apps
Answer
Short answer
Factor III, "Config", says: store configuration that varies between environments — database URLs, credentials, external service addresses, feature flags — in the environment (environment variables), not in the code. The same build must run in every environment with only its config changing.
The test
Could you make the codebase open source right now without leaking any credentials? If not, config is mixed into code.
Example
# dev
DATABASE_URL=postgres://dev@localhost/shop
# prod (injected from a Secret)
DATABASE_URL=postgres://[email protected]/shop?sslmode=require
Same image, different environment.
Related factors DevOps engineers quote
- Build, release, run — strictly separate stages; a release = build + config.
- Logs — treat logs as event streams written to stdout.
- Disposability — fast startup and graceful shutdown.
- Dev/prod parity — keep environments as similar as possible.
What to say in the interview
"Twelve-factor's config principle says environment-specific settings live in environment variables, not code, so one artifact runs everywhere. In Kubernetes that means ConfigMaps and Secrets mapped to env vars."
More on Database connections in apps
How does an application connect to a database, and how should connection details be passed?BeginnerAfter deployment, the app can't connect to the database. How do you troubleshoot it?IntermediateWhat is a connection string? Explain its parts.BeginnerWhat are the default ports for common databases?BeginnerWhy should database credentials never be stored in code or Git?BeginnerHow do Kubernetes Secrets work, and are they secure?Intermediate