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.
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.
"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."
| 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) |
| 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 |
| 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 |
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.
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
Red flags
Down() without thoughtT+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.
Rollback is only safe if version N-1 works with whatever N changed:
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.
Down() in productionEF Core Down() methods are generated for development. On production they can:
Prefer roll-forward migrations: a new migration that restores what you need, reviewed like any other change.
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.
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.
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.
Down(); note what data it would lose.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
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.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 |
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.
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.
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.
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%].
Last updated 23 Nov 2026.