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."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Connecting apps to databases

More on Database connections in apps