Deploy & Rollback Strategies
Compare rolling, blue-green, canary, feature flags, expand/contract DB migrations, and rollback vs roll-forward, using this site's planned Workers flow.
TL;DR
Choose your rollout strategy by blast radius: rolling updates replace instances gradually, blue-green swaps two full environments for instant cutover, and canary sends a small traffic slice (e.g., 5%) to the new version first. Keep DB migrations expand/contract so rollbacks don't break schemas.
Intent
Pick the right deployment and rollback strategy for your app's risk profile, decouple code deploys from feature releases with flags, and avoid breaking rollbacks with destructive schema changes.
Problem
Deploying a new version to 100% of users at once turns every missed edge case into a full outage. Worse, if a release drops a database column that the previous version still queries, hitting "rollback" fails too—leaving you stuck between two broken states.
Solution
1. Deployment strategies compared
| Strategy | How traffic shifts | Rollback speed | Extra capacity needed |
|---|---|---|---|
| Rolling | Replace N pods/VMs at a time | Medium (re-replace or rollout undo) | Small (maxSurge) |
| Blue-Green | Switch router from Blue (v1) to Green (v2) | Instant (flip router back to Blue) | 2x compute during deploy |
| Canary | Send 5% → 25% → 100% to v2 while watching SLOs | Instant (set v2 weight to 0%) | Small + traffic-splitting router |
2. Feature flags & expand/contract DB migrations
- Feature flags separate deploying code from releasing a feature. If a new checkout path misbehaves, you flip a flag off in seconds without a CI rebuild.
- Expand/contract migrations keep rollbacks safe:
- Expand: Add the new column/table as nullable while old code still writes the old column.
- Migrate & deploy: Dual-write or backfill, deploy code that reads the new column.
- Contract: Drop the old column only after you are confident you won't roll back.
3. Rollback vs roll-forward
- Roll back immediately when a new deploy causes a user-facing 5xx spike or latency regression—stop the bleeding first, debug second.
- Roll forward only when the fix is trivial and faster/safer than reverting, or when an irreversible data migration prevents running the old binary.
4. Real example: this site's planned Cloudflare Workers flow
In docs/deploy/CLOUDFLARE-WORKERS-PLAN.md (this workflow is planned and not live yet—the site currently builds as a static export and has not been deployed to learn.limmengty.com yet), PRs will upload an immutable preview version with wrangler versions upload while main deploys with wrangler deploy. If a production Worker deploy ever misbehaves, wrangler rollback (or gradual version splitting in the dashboard) reverts to the previous uploaded version in seconds.
Real-world analogy
▶ Flow: watch it work
Canary Deployment: 5% Traffic Slice & Health Gate
Press Start or tap any step dot to trace the path.
▸All steps (4)
Code
Planned Cloudflare Workers rollback and Kubernetes Deployment rollback commands:
# Planned Cloudflare Workers rollback (not run; site deploy is not live yet)
npx wrangler versions upload
npx wrangler rollback
# Kubernetes Deployment rollback to previous ReplicaSet (not run)
kubectl rollout undo deployment/webWhen you DON'T need this
- Low-traffic personal projects or static docs: A single
main-branch atomic deploy (like Cloudflare Pages/Workers static assets) is enough—running blue-green clusters or weighted canary traffic for 10 visitors/day adds complexity without statistical signal. - No observability: Canary deployments are pointless if you don't have metrics/error alerts comparing v1 vs v2; without telemetry, a 5% canary just breaks 5% of users silently.
- Cost / complexity trade-off: Rolling updates are built into Kubernetes and cheap. Blue-green doubles peak compute cost during deploys, and automated canary controllers (Argo Rollouts/Flagger) add CRDs, Prometheus queries, and traffic-mesh complexity.
When to use / when to avoid
- Production services where a bad release affects paying users or SLAs.
- Any schema change in a live database—always use expand/contract so rollback stays possible.
- Canary releases when traffic is too low to detect a 1% error rate within minutes.
- Destructive DROP COLUMN migrations in the same PR as application code changes.
How to implement
Make every deploy artifact immutable and versioned
Tag images by Git SHA (never :latest) or use versioned Worker uploads so you know exactly what to revert to.
Separate schema expansion from contraction
Ship additive DB changes first, deploy app code second, and drop old columns in a follow-up PR.
Practice the rollback path
Test kubectl rollout undo or wrangler rollback in staging before an incident forces you to learn it under pressure.
Pros / Cons
- Canary and blue-green reduce downtime and blast radius during risky releases.
- Expand/contract migrations keep instant code rollbacks safe.
- Blue-green temporarily doubles infrastructure capacity.
- Feature flags add conditional branches that must be cleaned up after rollout.
Relations
Check yourself
Check Yourself
1. Why should you avoid dropping an old database column in the same deploy that stops reading it?
2. What is the main advantage of a canary release over an all-at-once deploy?
Sources
Related Notes
OIDC in CI Instead of Long-Lived Keys
Use GitHub Actions OpenID Connect (OIDC) to mint short-lived cloud credentials on AWS, GCP, and Azure instead of storing static IAM keys in secrets.
CI/CD for This Site
How Mengty Learns validates the Next.js static build, tests hands-on labs, and collects weekly RSS inbox items using three GitHub Actions workflows.