CI/CD best practices: ship small, ship often, ship safely
How continuous integration and delivery work, the practices that make them effective, and how to measure progress.
Key takeaways
- Integrate to main at least daily. Long-lived branches are a hidden cost.
- Automate everything between commit and production.
- Decouple deploy from release with feature flags.
Continuous Integration (CI) means everyone merges small changes into the main branch frequently, with automated builds and tests. Continuous Delivery (CD) means every change that passes the pipeline could go to production at the push of a button, or automatically with continuous deployment.
#Core practices
#1. Trunk-based development
Short-lived branches (hours to a day or two) merged into main. Long-lived feature branches cause painful merges and delay feedback.
#2. Fast, reliable pipelines
- Under 10 minutes to feedback for most changes.
- Run fast checks first: lint, type check, unit tests.
- Parallelize, and cache dependencies.
- Zero tolerance for flaky tests.
#3. Build once, deploy many
Build an immutable artifact (container image, bundle) once, then promote the same artifact through staging and production.
#4. Feature flags
Merge unfinished features hidden behind flags. Deploy (code in production) becomes separate from release (users see it). Clean up old flags regularly.
#5. Progressive delivery
Canary releases, percentage rollouts and automatic rollback when error rates rise.
#6. Infrastructure as code
Environments defined in code (Terraform, CloudFormation, Pulumi), reviewed like any other change.
#Measure with DORA metrics
Research behind the Accelerate book showed that speed and stability go together. Elite teams deploy on demand, have lead times under a day, low change failure rates and restore service in under an hour. See Metrics that matter.
#Common pitfalls
- "CI" that runs nightly. That's not continuous.
- Manual approval gates everywhere. Automate checks, keep humans for real risk.
- Staging that doesn't match production. Bugs hide in the difference.
- No rollback plan. Every deploy should be reversible in minutes.
AI tip: AI agents are excellent at writing and fixing pipeline configs. Still review them carefully: pipelines hold secrets and production permissions.
Keep reading
Five principles for code that is easy to change, each explained with a short example and a warning about overuse.
The small daily habits that make code easy to read, review and change.
How many tests of which kind, how to write tests that catch real bugs, and how AI changes testing.