Dev/prod parity
Keep development, staging and production as alike as possible, so code that works on your laptop works in production.
On this page
Keep development, staging, and production as similar as possible. Most "works on my machine" bugs come from a gap between where code is written and where it runs. Twelve-factor names three gaps, and closes each one.
| Gap | Traditional app | Twelve-factor app |
|---|---|---|
| Time between writing code and deploying it | Weeks or months | Hours or minutes |
| Personnel: who writes it and who deploys it | Developers write, ops engineers deploy | The developers who wrote it deploy it and watch it run |
| Tools in development and production | SQLite and a laptop; Postgres and Linux in production | The same database, versions and OS in both |
1.Close the tools gap
Development runs the same Postgres version as production, in a container, instead of a lighter substitute.
#Use the real backing services locally
It's tempting to use SQLite on your laptop and Postgres in production, because SQLite needs no setup. But they differ in types, locking and SQL, and those differences surface as production-only bugs.
Containers make the real thing almost as easy:
services:
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: devpassword
ports: ['5432:5432']
cache:
image: redis:7
ports: ['6379:6379']docker compose up -d
export DATABASE_URL=postgres://postgres:devpassword@localhost:5432/postgresPin the same major versions you run in production, and update both together.
Referenced by