The Hook (The "Byte-Sized" Intro)
You deployed v2.0.0. Users are reporting crashes. You need to go back to v1.9.0 — now. A rollback strategy isn't something you design during the fire. It's planned in advance, tested regularly, and executed calmly when needed. Three approaches: redeploy the old artifact, revert the commits, or hotfix. Know which fits your situation.
📖 What is a Rollback Strategy?
A rollback strategy is a pre-planned approach for returning to a previously known-good version when a production deployment causes issues.
Conceptual Clarity
Three rollback approaches:
| Approach | How It Works | Speed | Risk |
|---|---|---|---|
| Artifact redeploy | Deploy the previous release's artifact | ⚡ Fastest | ✅ Lowest (already tested) |
| Git revert | Create new commits that undo changes | 🔨 Medium | 🟡 Medium (needs testing) |
| Hotfix | Fix the specific issue | 🐌 Slowest | 🟠 Higher (new code) |
When to use which:
| Situation | Best Approach |
|---|---|
| Previous artifact available | Artifact redeploy |
| Database migrations prevent redeploy | Git revert |
| Only one feature is broken | Hotfix |
| Need to keep forward-moving history | Git revert |
Real-Life Analogy
Rollback strategies are like fire escape plans. Nobody expects a fire, but everyone knows which exit to use. The plan exists before the emergency, is practiced regularly, and executed calmly when needed.
Visual Architecture
Why It Matters
- Speed: The faster you rollback, the less impact on users.
- Confidence: A tested rollback plan reduces panic.
- Data safety: Database migrations add complexity — plan for them.
- Culture: Teams that practice rollbacks deploy more confidently.
Code
# ─── Approach 1: Artifact redeploy (fastest) ───
# Deploy the previously-built artifact for v1.9.0
# (No Git commands needed — just point deployment at the old artifact)
# ─── Approach 2: Git revert ───
# Find commits between the two releases
git log v1.9.0..v2.0.0 --oneline
# Revert them (newest first)
git revert v2.0.0..v1.9.0 # Reverts in reverse order
# Or revert the merge commit
git revert -m 1 <merge-commit-sha>
# Push and deploy
git push origin main
# ─── Approach 3: Hotfix ───
git checkout -b hotfix/v2.0.1 v2.0.0
# Fix the specific issue
git commit -m "fix: resolve crash on login"
git tag -a v2.0.1 -m "Hotfix for login crash"
git push origin v2.0.1
# ─── Pre-planning: test your rollback ───
# 1. Document the rollback process
# 2. Practice in staging first
# 3. Ensure previous artifacts are retained
# 4. Test database rollback migrationsKey Takeaways
- Plan rollbacks before you need them — not during the incident.
- Artifact redeploy is fastest and safest when available.
- Git revert is best when you must maintain forward-only history.
- Consider database migrations — they may prevent simple rollbacks.
Interview Prep
-
Q: What is the fastest way to rollback a production deployment? A: Redeploying the previously-built and tested artifact (e.g., the v1.9.0 Docker image). No rebuilding needed, and the artifact is already tested. This requires retaining artifacts from previous releases.
-
Q: When would you use
git revertinstead of artifact redeploy? A: When you can't redeploy the old artifact (e.g., irreversible database migrations), when you need the rollback recorded in Git history, or when the deployment system only deploys from Git. -
Q: Why should rollback strategies be planned and tested in advance? A: During an incident, stress leads to mistakes. A pre-tested plan can be executed quickly and calmly. Testing also reveals issues like database migration dependencies that would complicate a real rollback.