Deployment Environments
Managing development, staging, and production environments — environment parity, environment-specific configuration, and best practices.
What is a deployment environment?
A deployment environment is a complete instance of the system configured for a specific purpose. Each environment has its own infrastructure, databases, external services, and configuration, but ideally runs the same code.
The typical environments in a software project are:
- Development (dev): where developers do their day-to-day work
- Staging: a replica as faithful as possible to production for final testing
- Production (prod): the real environment used by end users
Development environment
The development environment is where the team writes, tests, and debugs code. Its main characteristics are:
- Iteration speed: changes are reflected quickly
- Test data: fake data or seeds are used to simulate scenarios
- Local or mock services: local databases, in-memory queues, simulated APIs
- Verbose logs: logging level set to DEBUG to make debugging easier
It’s common to use tools like Docker Compose to spin up the entire stack locally with a single command.
Staging environment
Staging is the last step before production. Its goal is to validate that everything works under conditions as close as possible to the real environment.
- Parity with production: same infrastructure, same service versions, same network configuration
- Representative data: anonymized or generated data that reflects real volumes and patterns
- Integration testing: validate that all services communicate correctly
- Performance testing: run load tests to detect bottlenecks
Production environment
Production is the environment that serves end users. It requires the highest level of care:
- High availability: redundancy, load balancing, automatic failover
- Continuous monitoring: metrics, alerts, real-time dashboards
- Structured logs: JSON format, request correlation, adequate retention
- Automatic backups: regular backups of databases and configuration
- Restricted access: only authorized personnel can access directly
Environment parity
One of the most important principles of modern deployment is environment parity. The idea is to minimize the differences between dev, staging, and production.
Why does it matter?
When environments differ significantly, bugs only show up in production — the worst place to discover them. The common differences that cause problems are:
- Different versions of databases or services
- Different network configuration (ports, DNS, certificates)
- Very different data volumes
- Different operating systems or runtimes
How to achieve parity
- Containers: use Docker so the same artifact runs across all environments
- Infrastructure as Code: define infrastructure with Terraform, Pulumi, or CloudFormation
- Externalized configuration: differences between environments are handled solely through environment variables
- Consistent pipelines: the same CI/CD pipeline deploys to all environments
Per-environment configuration
Each environment needs specific configuration. The key is to separate configuration from code:
# .env.development
DATABASE_URL=postgres://localhost:5432/myapp_dev
LOG_LEVEL=debug
API_URL=http://localhost:3000
# .env.staging
DATABASE_URL=postgres://staging-db:5432/myapp_staging
LOG_LEVEL=info
API_URL=https://staging-api.example.com
# .env.production
DATABASE_URL=postgres://prod-db:5432/myapp_prod
LOG_LEVEL=warn
API_URL=https://api.example.com
Best practices
- Never hardcode environment-specific values in the code
- Use environment variables for anything that changes between environments
- Keep an
.env.examplefile documenting all the required variables - Secrets never go in configuration files — use a secrets manager
Promotion strategies
Promotion is the process of moving code from one environment to the next:
- Dev → Staging: automatic after passing tests in CI
- Staging → Production: manual or automatic depending on the team’s maturity
The artifact being promoted must be exactly the same — it is not recompiled between environments. Only the configuration changes.
Summary
| Aspect | Dev | Staging | Production |
|---|---|---|---|
| Data | Fake/seeds | Representative | Real |
| Access | Open to the team | Restricted | Highly restricted |
| Monitoring | Basic | Full | Full + alerts |
| Logs | DEBUG | INFO | WARN/ERROR |
| Deployment | Continuous | Automatic | Controlled |