Deployment Strategies and Feature Flags
Release changes with rolling, blue-green and canary deployments, decouple deploy from release with feature flags, and roll back fast.
Intermediate · about 6 hours · difficulty 3/5
Learn first: Continuous Integration and Delivery, Workloads, Probes and Autoscaling
Deploying is putting new code on servers; releasing is exposing it to users. Good strategies keep those separate and limit how many users a bad change can hurt.
Strategies
- Recreate: stop old, start new. Simple, but causes downtime.
- Rolling: replace instances a few at a time (Kubernetes Deployments do this by default with
maxSurgeandmaxUnavailable). Old and new versions run side by side briefly, so they must be compatible. - Blue-green: run a full new environment (green) next to the current one (blue), test it, then switch traffic at the load balancer or DNS. Rollback is switching back. Costs double capacity during the switch.
- Canary: send a small slice of traffic (1%, 5%, 25%) to the new version, compare error rates and latency with the baseline, and continue or abort. Tools such as Argo Rollouts and Flagger automate the analysis.
- Shadow / mirroring: copy live traffic to the new version without returning its responses.
Feature flags
Wrap new behaviour in a flag so code can ship dark and be turned on per user, percentage or region, without a deploy. Flags enable trunk-based development, quick kill switches and A/B tests. Services include LaunchDarkly, Unleash, Flagsmith and the vendor-neutral OpenFeature SDK. Remove flags once a feature is fully launched, or they become debt.
Making rollbacks boring
Keep database migrations backward compatible (expand, migrate, contract), keep the previous artifact ready, and automate rollback on failed health checks.
Good enough to move on: you can choose a strategy for a given service and explain its cost, run a canary with automated metric checks, and ship a feature behind a flag with a kill switch.
Key concepts
- Deploy vs release
- Recreate and rolling updates
- Blue-green deployments
- Canary releases and analysis
- Traffic mirroring
- Feature flags and OpenFeature
- Argo Rollouts and Flagger
- Automated rollback
Mini project
On a local Kubernetes cluster, install Argo Rollouts and run a canary that shifts traffic in steps and aborts automatically when a Prometheus error-rate query crosses a threshold. Add a feature flag to toggle one endpoint without redeploying.
Check yourself
Why must old and new versions be compatible during a rolling update, and what does that imply for database schema changes?
Free resources
- Kubernetes: performing a rolling update (kubernetes.io)
- Argo Rollouts (Argo Project)
- OpenFeature documentation (OpenFeature)