Rollback Strategies for Zero-Downtime
Version retention, database reversibility, and automated rollback triggers for safe recovery.
Why
When a deploy breaks production, every minute of downtime costs revenue and trust. A pre-tested rollback path — old version retained, DB migrations reversible, trigger automated — restores service in seconds instead of hours of 'fix-forward' panic.
Rollback must be a first-class deploy operation, not an afterthought.
When
Implement formal rollback for any production system with SLAs, frequent deploys (>1/day), or stateful data. Skip for static sites where redeploy is instant and stateless.
How
Example
Common Problems
- ⚠Old version GC'd — registry retention too short, rollback target gone, forced to fix-forward
- ⚠Irreversible migration — added NOT NULL column, old version crashes on rollback, must fix-forward
- ⚠Rollback never tested — works in theory, fails in practice (config drift, missing env var)
- ⚠Fix-forward culture — team never rolls back, so the path rots and panic-fixing takes hours
Best Practices
- ✓Set revisionHistoryLimit: 5+ and registry retention 90 days — rollback target always available
- ✓Prefer feature flags over redeploy rollback — instant, no version juggling, no DB concerns
- ✓Run a 'rollback drill' monthly — deploy to staging, break it, roll back, verify the path works
- ✓Make every migration reversible — expand/contract, never destructive in the same deploy as code
FAQ
How fast should a rollback be?
Under 5 minutes — if it takes longer, users suffer while you investigate. Pre-bake the previous image/version so rollback is a single command (kubectl rollout undo). Never rebuild from an old commit during an incident.
What's the difference between rollback and fix-forward?
Rollback reverts to the last known-good version (fast, safe). Fix-forward deploys a new version that fixes the bug (slower, but keeps history clean). Rollback first to stop the bleeding, then fix-forward in a follow-up deploy.
How do I handle rollbacks with database changes?
Additive migrations (new columns) are rollback-safe. Destructive migrations (drop column) are not — you can't restore the data. Apply destructive changes in two phases: deploy code that stops writing, then drop the column after a safe period.
Why do I need to test my rollback?
Untested rollbacks fail when you need them most. Run a rollback in staging every release — it catches issues like incompatible DB schemas, missing images, or config that only exists in the new version. A rollback is a deploy; test it like one.
How do I automate rollback on error spikes?
Use Flagger or Argo Rollouts with a metric provider (Prometheus). Set: if error rate exceeds 1% for 2 min, auto-rollback. This catches issues in seconds vs. an on-call engineer taking 10 min to notice and act.