Environments
Development, staging and production environments that behave alike.
Environments let changes be tested before they reach users. Differences between them cause surprises in production. Configuration as code and preview environments per change reduce that drift.
Why it matters for a product engineer
Environments let a change be tested before it reaches users. Each difference between them is a place where something works in testing and fails in production. A product engineer who keeps environments alike, and keeps them apart, finds problems earlier and protects real users and real data.
How to do it
- Keep development, staging and production as similar as possible: the same database engine, the same queue, the same versions.
- Put configuration in the environment, not in the code, and define the environments themselves as code.
- Build once, and deploy the same artifact everywhere. Only the configuration changes.
- Give each change its own preview environment when you can, so reviewers can try it.
- Keep production data and production services out of test environments: separate keys, separate analytics, separate email.
- Make the current environment obvious, in the interface and in the terminal.
Common mistakes
- SQLite in development and PostgreSQL in production.
- A staging environment that nobody keeps up to date.
- Test traffic in production analytics, or test emails sent to real users.
- Copying production data, with personal details, into development.
Example
This site runs in three places: a developer’s machine, a local preview of the built site, and
production. The same build runs in all three. Analytics send only from a production build on
productengineer.pro, so local, preview and agent runs never reach the real collector. Locally, the
API offers a development sign-in, turned on with DEV_LOGIN=1, so nobody needs a real GitHub or
Google account to test it.
Three gaps between development and production
| Traditional app | Twelve-factor app | |
|---|---|---|
| Time between deploys | Weeks | Hours |
| Who writes and who deploys | Different people | The same people |
| Dev and production environments | Divergent | As similar as possible |
Environments drift apart through time, people and tools. Frequent deploys by the people who wrote the code keep all three gaps small.
ReportedAdam Wiggins, The twelve-factor app
Resources
1- articleStart here
The twelve-factor app ↗
Adam Wiggins (Heroku) · 30 minTwelve short rules for building services that deploy and scale cleanly, still the common baseline.
Tools
1- ToolFreemium
GitHub Actions
CI/CD built into GitHub, for running tests, checks and deployments on every change.