{
    "slug": "deployment_rollback",
    "term": "Deployment Rollback Strategies",
    "category": "devops",
    "difficulty": "intermediate",
    "short": "Strategies for reverting a broken deployment quickly — from git revert and re-deploy to instant traffic switching with blue-green or feature flags.",
    "long": "Rollback options by speed: Feature flags (instant — flip a flag without deploying), Blue-green (instant — switch load balancer to previous environment), Canary (fast — redirect canary traffic to stable), Git revert + redeploy (minutes — depends on CI/CD pipeline speed), Database rollback (slow, risky — migrations may not be reversible). The fastest rollback is the one already in place before the deploy. Database migrations that are not reversible are the most common rollback blocker — always write forward-compatible migrations first.",
    "aliases": [
        "rollback",
        "revert deployment",
        "undo deploy"
    ],
    "tags": [
        "devops",
        "ci-cd",
        "reliability"
    ],
    "misconception": "You can always roll back by reverting the git commit — database schema changes that have already run cannot be rolled back by reverting code; the schema is still modified.",
    "why_it_matters": "A deployment that breaks production needs to be fixed in minutes, not hours — pre-planned rollback strategies are the difference between a 5-minute incident and a 2-hour outage.",
    "common_mistakes": [
        "Irreversible database migrations — always add columns before removing old ones; never rename in one step.",
        "No rollback testing — rollback procedures that have never been tested will fail when needed most.",
        "Assuming git revert is sufficient — code reverted, DB schema already migrated — app breaks with old code on new schema.",
        "Rolling back without investigating root cause — rollback buys time; the fix still needs to be understood."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "blue_green_deployment",
        "feature_flag",
        "continuous_deployment",
        "database_migrations"
    ],
    "prerequisites": [
        "blue_green_deployment",
        "continuous_deployment",
        "database_migrations"
    ],
    "refs": [
        "https://martinfowler.com/bliki/BlueGreenDeployment.html"
    ],
    "bad_code": "# Breaking migration with no rollback path:\nALTER TABLE users RENAME COLUMN email TO email_address;\n# Old app code: SELECT email FROM users — now broken\n# Rolling back the code: still broken, schema changed\n# Only fix: another migration or forward-fix deploy",
    "good_code": "# Forward-compatible migration — allows rollback:\n# Step 1: Add new column (app still uses old column):\nALTER TABLE users ADD COLUMN email_address VARCHAR(254);\nUPDATE users SET email_address = email;\n\n# Step 2: Deploy app reading both columns (backwards compatible)\n# Step 3: Deploy app using only new column\n# Step 4: Drop old column in a later migration\n# Rollback possible at any step except after step 4",
    "quick_fix": "Test your rollback procedure in staging monthly — a rollback you've never practiced is a rollback that won't work at 2am during an incident",
    "severity": "high",
    "effort": "medium",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/deployment_rollback",
        "html_url": "https://codeclaritylab.com/glossary/deployment_rollback",
        "json_url": "https://codeclaritylab.com/glossary/deployment_rollback.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Deployment Rollback Strategies](https://codeclaritylab.com/glossary/deployment_rollback) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/deployment_rollback"
            }
        }
    }
}