Lesson Completion
Back to course

Rollback Strategy

Intermediate
8 minutes4.8Git

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:

ApproachHow It WorksSpeedRisk
Artifact redeployDeploy the previous release's artifact⚡ Fastest✅ Lowest (already tested)
Git revertCreate new commits that undo changes🔨 Medium🟡 Medium (needs testing)
HotfixFix the specific issue🐌 Slowest🟠 Higher (new code)

When to use which:

SituationBest Approach
Previous artifact availableArtifact redeploy
Database migrations prevent redeployGit revert
Only one feature is brokenHotfix
Need to keep forward-moving historyGit 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

flowchart TD PROBLEM["🔥 Bad deployment v2.0.0"] --> PREVIOUS{"Previous artifact available?"} PREVIOUS -->|"Yes"| REDEPLOY["⚡ Redeploy v1.9.0 artifact"] PREVIOUS -->|"No"| MIGRATION{"DB migrations?"} MIGRATION -->|"No"| REVERT["🔨 Git revert + deploy"] MIGRATION -->|"Yes"| HOTFIX["🩹 Hotfix on v2.0.0"] style PROBLEM fill:#2d1b1b,stroke:#e94560,color:#e94560 style REDEPLOY fill:#1b2d1b,stroke:#53d8fb,color:#53d8fb

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

bash
# ─── 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 migrations

Key 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 revert instead 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.

Topics Covered

Git RecoveryDeployment

Tags

#git#rollback#deployment#production

Last Updated

2026-02-13