Deployment Strategies and Safe Releases
Release without downtime using rolling, blue/green and canary deployments, feature flags and automatic rollback on alarms.
Advanced · about 4 hours · difficulty 3/5
Learn first: CI/CD Concepts and Pipeline Design, AWS Lambda Functions
Most outages are caused by changes. Good deployment strategies limit how many users a bad release can hurt and make rollback fast.
Strategies
- Recreate: stop old, start new. Simple, causes downtime. Only for dev.
- Rolling: replace instances or tasks a few at a time. Default for ECS and ASG instance refresh.
- Blue/green: run the new version alongside the old, switch traffic at the load balancer, switch back instantly if needed. CodeDeploy supports this for ECS, EC2 and Lambda.
- Canary: send a small slice (say 10 percent) of traffic to the new version, watch metrics, then shift the rest. Lambda aliases with weighted routing and ALB weighted target groups make this easy.
- Feature flags (AWS AppConfig, LaunchDarkly, Unleash) separate deploying code from releasing a feature.
Automatic rollback
Attach CloudWatch alarms (error rate, latency) to the deployment. If an alarm fires during the bake time, CodeDeploy or the ECS circuit breaker rolls back without a human.
Database changes
Schema changes must be backward compatible during a rollout: add columns first, deploy code that uses them, remove old columns later (expand and contract).
Pitfalls
- Blue/green with a shared database migration that breaks the old version.
- Canary periods too short to collect meaningful metrics.
- No tested rollback plan.
You are ready to move on when you can run a canary release of a Lambda function that automatically rolls back when an error alarm fires.
Key concepts
- Rolling deployments
- Blue/green deployments
- Canary and linear deployments
- Lambda aliases and weighted routing
- Alarm-based automatic rollback
- Feature flags with AppConfig
- Expand and contract migrations
Mini project
Deploy two versions of a Lambda behind an alias with CodeDeploy using a Canary10Percent5Minutes configuration and an alarm on the error metric. Deploy a version that throws errors and watch it roll back automatically. Free-tier sized; delete the function, alias and deployment group afterwards.
Check yourself
What is the difference between blue/green and canary deployments, and when would you choose each?