📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Tell me about a deployment that broke production. How did you decide between rolling back and rolling forward, what did you do about database changes that had already run, and what did you change in the pipeline afterwards?

A failed production deployment end to end: detection, the roll back vs roll forward decision, handling migrations that already ran, communication, and the pipeline and process changes that followed.

Senior RealWorldScenario Advanced ci-cd deployment-safety devops ef-core-migrations incident-response rollback

🎯 Key points

  • Detect fast with automated alerts on 5xx ratio and p95 latency split by version, release annotations and post-deploy smoke tests
  • Mitigate first, diagnose later: restore service before finding root cause
  • Roll back when the previous version is compatible with current schema, messages, caches and config; roll forward only when it isn't or the fix is tiny and certain
  • Feature flag kill switch is often faster than either, if the change was flagged
  • Migrations that ran: keep additive changes, never run EF Core Down() blindly on production; PITR to a new database for corrupted data
  • Configuration is versioned and deployed with the release (IaC, App Configuration labels) so rollback restores matching config
  • Communicate on a fixed rhythm; blameless review with owned, tracked actions
  • Measure with DORA: change failure rate and time to restore

⏱ 30-second answer

First I mitigate, then diagnose. Alerts on 5xx and latency, annotated with the release, tell us the deployment is the likely cause. Then the key decision: roll back if the previous version still works with the current database and messages; roll forward only if rollback is unsafe (a contract change already happened) or the fix is tiny and certain. A feature flag kill switch beats both if the change was flagged.

For migrations that already ran, I don't run down migrations on live data; additive changes stay, and if something destructive ran I restore compatibility (a view or computed column) or use point-in-time restore for the affected data.

Afterwards: a blameless review and pipeline changes such as smoke tests, staged rollout, migration checks and automated rollback. The trade-off is speed of recovery versus certainty about cause.

🗣 Full answer (senior)

How I would answer this in an interview

"I'll use a real example, and I'll go through it as detect, decide, recover, then improve. At [company] we deployed a release of our [orders API] on a [Thursday afternoon]. Within about [four minutes] our Application Insights alert on HTTP 5xx fired, and the release annotation lined up exactly with the spike: [around 18%] of order submissions were failing with a null reference in the new pricing code.

The first decision was roll back or roll forward. My rule is: roll back if the previous version is compatible with everything the new one has changed, because a rollback is a known-good state; roll forward only when rolling back is unsafe or the fix is a one-line change we're certain about. Here the release had run one migration, which added a nullable column; the old code ignores it, so rollback was safe. We swapped the App Service slots back, which put the previous build, still warm, into production, and errors were gone in under a minute. I posted in the incident channel and the status page as we went. We didn't run the down migration: the extra column was harmless, and running Down() on production data under pressure is how you turn an outage into data loss.

The mistake I see is teams debugging in production while customers fail, because they want to understand the cause first. Restore service, then investigate. Afterwards we ran a blameless review. The root cause was a pricing rule with a missing default that our tests didn't cover, but the systemic causes were that we deployed to 100% at once with no smoke test of the order path. We added a synthetic order test after deploy that triggers an automatic swap-back, moved risky features behind flags, and added a pipeline check that blocks destructive migrations without an explicit label. Our change failure rate went from [about 12% to 4%] over the next quarter."


The decision: roll back, roll forward or switch off

Option Use when Avoid when Typical speed
Feature flag off The broken path is behind a flag The fault is outside the flagged code Seconds
Roll back (swap back, previous revision, rollout undo) Previous version is compatible with current schema, messages and config A breaking migration or contract change already ran Seconds to minutes
Roll forward (hotfix) Rollback unsafe, or fix is trivial, reviewed and fast through the pipeline Root cause unclear; pipeline takes 40 minutes Minutes to hours
Restore data Data was corrupted or deleted Only code is wrong Minutes to hours (PITR)

Handling migrations that already ran

What ran What I do
Additive (new table, nullable column, index) Leave it; old code ignores it
Data backfill that's wrong Stop the job; fix data with a reviewed script from the audit trail or PITR copy
Rename / drop Restore compatibility quickly (view, computed column, re-add column), then plan a proper expand/contract
Data deleted Azure SQL point-in-time restore to a new database, copy back the affected rows

Communication

  • Declare an incident early with an owner (incident lead) and a scribe for the timeline.
  • Post updates on a fixed rhythm (for example every 15 minutes) to stakeholders and the status page.
  • If personal information may have been exposed or corrupted, involve the privacy officer for a Notifiable Data Breaches assessment.

What changed in the pipeline

Gap found Change
No check after deploy Synthetic transaction smoke test; automatic swap-back on failure
100% exposure at once Canary or traffic routing to 10% for 15 minutes before full swap
Destructive migrations slipped through Pipeline scans the migration SQL for DROP/sp_rename and requires approval
Slow detection Release annotations, alerts per version
Untested path Tests added for the bug class, not just the bug

Production example

In this kind of incident, the difference between a 1-minute and a 45-minute outage is almost always whether rollback was safe and rehearsed. After the changes above, the team's median time to restore for deployment-caused incidents dropped from about 35 minutes to 6.

🔍 What the interviewer is checking

Checks whether the candidate has real incident experience: mitigation before diagnosis, a principled rollback decision, care with production data, and systemic follow-up.

Green flags

  • Mitigates first and uses flags or rollback before debugging
  • Explains the roll back vs roll forward decision with compatibility checks
  • Won't run down migrations on live data; knows PITR to a new database
  • Describes concrete pipeline changes and measures the improvement

Red flags

  • Story with no numbers, no decision process or blames a colleague
  • Restores a backup over production or runs Down() without thought
  • No follow-up changes, or "we just tested more carefully"

📚 Learn in depth

1. The incident timeline

T+0     deploy completes (release annotation)
T+2     5xx alert fires (version-tagged telemetry)
T+4     incident declared, lead assigned
T+5     decision: is rollback safe?  ── check migrations, contracts, config
T+6     mitigate: flag off / swap back / previous revision
T+7     verify: error rate back to baseline, synthetic test green
T+30    comms: resolved notice; data impact assessed
T+2d    blameless review → actions with owners and dates

The two numbers to shrink are time to detect and time to mitigate. Root cause can wait.

2. Why rollback safety is decided before the deploy

Rollback is only safe if version N-1 works with whatever N changed:

  • Schema: N's migrations must be additive (expand/contract).
  • Messages: N must not publish events N-1 consumers can't read; N-1 must tolerate events N wrote to queues.
  • Caches and stored state: serialised objects in Redis or blob storage written by N must be readable by N-1.
  • Config: new required settings must have defaults or be added before N.

If any of these break, rollback is no longer an option and you're forced to roll forward under pressure. That's why many teams make "N-1 compatible" a PR checklist item.

3. Why not run Down() in production

EF Core Down() methods are generated for development. On production they can:

  • drop columns that now hold new data (data loss),
  • take long schema locks on large tables,
  • fail halfway, leaving the schema in neither state.

Prefer roll-forward migrations: a new migration that restores what you need, reviewed like any other change.

4. Point-in-time restore

Azure SQL keeps automated backups with point-in-time restore (7 days by default, configurable up to 35). Restore to a new database at a time before the bad deploy, then copy back only the affected rows with a reviewed script. Never restore over the live database: you'd lose every legitimate write since that time.

5. Automated rollback

deploy to staging slot ─► warm-up ─► swap ─► synthetic order test (5 min)
                                              │ fail
                                              ▼
                                     swap back automatically ─► page on-call

On Container Apps, shift traffic back to the previous revision; on AKS, Argo Rollouts aborts a canary when its analysis fails.

6. Blameless review

Ask "what made this easy to get wrong?" rather than "who did it?". Output: a timeline, contributing factors (technical and process), and 3–5 actions with owners. Track whether actions are done; an unfinished action list is how the same incident happens twice.

Try it yourself

  1. Write the rollback decision for your current service as a checklist: schema, messages, caches, config.
  2. In a test App Service, deploy a broken build to staging, swap, and time how long a swap-back takes.
  3. Generate an EF Core migration that renames a column and read its Down(); note what data it would lose.
  4. Run an Azure SQL point-in-time restore to a new database and copy back one table.
  5. Add a release annotation to Application Insights from your pipeline and check it appears on the failures chart.

💻 Code

A synthetic post-deploy check the pipeline runs; a non-zero exit triggers the automatic swap-back (tools/SyntheticOrderCheck/Program.cs):

using System.Net.Http.Json;

var baseUrl = Environment.GetEnvironmentVariable("TARGET_URL")
    ?? throw new InvalidOperationException("TARGET_URL is required");

using var http = new HttpClient { BaseAddress = new Uri(baseUrl), Timeout = TimeSpan.FromSeconds(10) };
using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));

var failures = 0;
for (var i = 0; i < 20 && !cts.IsCancellationRequested; i++)
{
    try
    {
        // A test-tenant order exercises pricing, persistence and messaging end to end.
        var response = await http.PostAsJsonAsync("/orders",
            new CreateOrder("synthetic-tenant", "SKU-TEST", 1), cts.Token);
        if (!response.IsSuccessStatusCode) failures++;
    }
    catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException)
    {
        failures++;
    }
    await Task.Delay(TimeSpan.FromSeconds(10), cts.Token);
}

Console.WriteLine($"Synthetic orders failed: {failures}/20");
return failures > 1 ? 1 : 0; // allow one transient failure

public sealed record CreateOrder(string Tenant, string Sku, int Quantity);

The pipeline steps around it:

      - name: Swap staging into production
        run: az webapp deployment slot swap -g rg-orders-prod-aue -n app-orders-prod-aue --slot staging
      - name: Synthetic order check
        id: synthetic
        run: dotnet run --project tools/SyntheticOrderCheck -c Release
        env: { TARGET_URL: https://orders.contoso.com.au }
      - name: Automatic rollback
        if: failure() && steps.synthetic.outcome == 'failure'
        run: az webapp deployment slot swap -g rg-orders-prod-aue -n app-orders-prod-aue --slot staging

A guard that blocks destructive migrations unless the PR is labelled for it:

dotnet ef migrations script --idempotent -o migration.sql --project src/Orders.Infrastructure
if grep -Ei 'DROP (TABLE|COLUMN)|sp_rename' migration.sql && [[ "$PR_LABELS" != *contract-phase* ]]; then
  echo "Destructive migration found. Use expand/contract or label the PR contract-phase."; exit 1
fi

⚠ Common mistakes

  • Mistake: Diagnosing the root cause while customers keep failing. Why it is wrong: Every minute of investigation is a minute of outage. Instead: Mitigate first (flag off, roll back), then investigate.
  • Mistake: Rolling back without checking compatibility. Why it is wrong: If the release changed the schema or message contracts, the old version fails too. Instead: Check schema, messages, caches and config before choosing rollback.
  • Mistake: Running EF Core Down() migrations on production. Why it is wrong: It can drop new data and lock large tables. Instead: Leave additive changes; restore compatibility with a new forward migration.
  • Mistake: Restoring a backup over the live database. Why it is wrong: All legitimate writes since the restore point are lost. Instead: Point-in-time restore to a new database and copy back affected rows.
  • Mistake: Hotfixing straight to production, skipping the pipeline. Why it is wrong: An untested fix under pressure often causes a second incident. Instead: Use the normal pipeline, with an expedited review.
  • Mistake: Going quiet during the incident. Why it is wrong: Stakeholders escalate and support is blind. Instead: Regular updates on a fixed rhythm.
  • Mistake: A post-incident review that blames a person. Why it is wrong: People hide mistakes and systemic causes stay. Instead: Run it blameless and focus on what made the error easy.
  • Mistake: Review actions that are never finished. Why it is wrong: The same failure repeats. Instead: Give actions owners and dates and track them.

🏛 Senior insight: trade-offs

Seniors don't just fix the bad deploy; they make the next one cheaper to undo. That means deciding rollback safety before deploying (N-1 compatibility for schema, messages, state and configuration), having a rehearsed one-command rollback, and detecting by version so the decision takes minutes, not an hour of debate.

The hard judgement call is roll back versus roll forward. My bias is strongly towards rollback or a kill switch, because they return to a known state; roll forward feels faster but stacks a second untested change on top of the first. I measure the outcome with DORA's change failure rate and time to restore, and I check that review actions actually land.

I also make rollback a team skill, not a hero skill. After an incident I run the review with everyone who was involved, and we turn the findings into shared assets: a rollback runbook in the repo, the N-1 compatibility item in the PR template, and a quarterly "game day" where a different engineer deliberately deploys a broken build to staging and practises the swap-back and data checks. The goal is that the most junior person on call can roll back calmly at 2 am.

Option When it fits Cost When not to
Feature flag off Risky features shipped dark Flag discipline The bug is outside the flag
Rollback N-1 compatible release Rehearsed process, warm previous version Breaking migration already ran
Roll forward Rollback unsafe or fix trivially certain A fast, trusted pipeline Cause not yet understood
Data restore (PITR to new DB) Corrupted or deleted data Time, careful merge Code-only failure

🔗 Follow-ups the interviewer may ask

  1. When: Candidate says the release went to 100% of traffic at once. Why: Checks whether the candidate can pick a deployment strategy that would have limited the blast radius.
    How to answer

    Rolling replaces instances in batches: no extra capacity, but old and new versions serve traffic together and rolling back means another rollout. Blue-green runs a full second environment and switches all traffic at once; rollback is switching back. Canary sends a small share of traffic (say 5%) to the new version, compares error rate and latency, then widens or aborts. App Service deployment slots are blue-green in a box: deploy to staging, warm it up, swap, and swap back to roll back.

    The catch is the same for all of them: for a while two versions run against one database, so schema changes must be expand/contract and backward compatible. The trade-off is cost and complexity (blue-green and canary) against blast radius and rollback speed.

  2. When: Candidate mentions a migration that made rollback unsafe. Why: Checks practical expand/contract knowledge for schema changes.
    How to answer

    Never use RenameColumn while old and new app versions overlap: the old version would query a column that no longer exists. Use expand and contract over several releases. 1. Expand: add the new column (nullable). 2. Dual write: release an app version that writes both columns in the same SaveChanges (same transaction), or add a trigger that copies writes made by the old version, and still reads the old column. 3. Backfill existing rows in small batches (UPDATE TOP (5000) ... WHERE New IS NULL) to avoid long locks and log growth, then verify with a count of mismatches. 4. Switch reads to the new column; keep writing both so a rollback to the previous version still works. 5. Contract: once no running version uses the old column, stop writing it and drop it in a later migration. Each step is backward compatible with the version before it.

  3. When: Candidate mentions a kill switch or feature flag. Why: Checks whether the candidate uses flags as a faster mitigation than rollback.
    How to answer

    A feature flag is a run-time switch around a code path. It lets you deploy code to production with the feature off and release it later by changing configuration, to a percentage of users or a group first.

    In .NET, Microsoft.FeatureManagement gives you IFeatureManager.IsEnabledAsync, [FeatureGate] for endpoints, and feature filters: Percentage, TimeWindow and Targeting (users, groups, rollout percentage), plus variants for experiments. Azure App Configuration stores the flags centrally and the app refreshes them without a redeploy, using managed identity to connect.

    The trade-off: flags make releases safe and reversible, but every flag doubles the paths to test. Release flags must have an owner and a removal date; only kill switches should live long.

🛠 Real-world problems: how you handle them

Pricing release broke order submission and was rolled back by slot swap
Situation
A .NET 10 orders API on App Service in Australia East handling [about 1,500 orders per hour]. A release with new pricing rules and one additive EF Core migration was swapped into production on a [Thursday afternoon].
Signals
Application Insights 5xx alert within [4 minutes]; failure rate on `POST /orders` at [about 18%]; exceptions `NullReferenceException` in `PricingEngine.Apply`; release annotation aligned with the spike; customer support tickets about failed checkouts.
Investigation
Application Insights Failures blade filtered by the new build's `application_Version`; exception details pointed to a pricing rule without a default; checked the release's migrations in the pipeline log (one nullable column added) to confirm rollback compatibility.
Resolution
Immediate: swapped slots back (previous build still warm), errors cleared in under a minute; left the additive column in place. Real fix: default handling plus tests for missing pricing rules, released two days later behind a feature flag and rolled out to 10% first.
Prevention
Synthetic order test after every swap with automatic swap-back; traffic routing to 10% for 15 minutes before full exposure; destructive-migration guard in the pipeline; N-1 compatibility item in the PR template; blameless review actions tracked to completion.

How to tell it (STAR)

**S:** We released new pricing rules to our orders API and [about 18%] of orders started failing within minutes. **T:** I was the incident lead and had to restore checkout and stop it happening again. **A:** I confirmed the only migration was additive, so I swapped the slots back instead of trying a hotfix, kept stakeholders updated every 15 minutes, then ran a blameless review that led to a post-deploy synthetic order test with automatic swap-back, a 10% exposure stage and a pipeline guard on destructive migrations. **R:** Orders recovered in [under a minute] after the decision, and over the next quarter our change failure rate fell from [about 12% to 4%].

↩ Usually asked after

More in CI/CD

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me