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

📚 Interview question

Compare rolling, blue-green and canary deployments, and Azure App Service deployment slots. What does each cost, how do you roll back with each one, and what does the database have to do to make any of them safe?

Deployment strategies for .NET services: rolling, blue-green, canary and App Service slots or Container Apps revisions, their costs, rollback paths and the backward-compatible database changes they require.

Mid-Level Theory Intermediate azure-app-service blue-green canary ci-cd deployment-strategies devops

🎯 Key points

  • Rolling: replace instances in batches; costs only surge capacity, but old and new run together and rollback is another rollout
  • Blue-green: full second environment, switch traffic at once; costs up to 2x compute during the window, rollback in seconds
  • Canary: send 1-10% of traffic to the new version; costs tooling plus per-version telemetry, smallest blast radius
  • App Service slots: deploy to staging, warm up, swap; Standard tier or higher, slots share the plan's instances
  • Slot-sticky settings and warm-up (applicationInitialization, WEBSITE_SWAP_WARMUP_PING_PATH) avoid cold starts and config mix-ups
  • Every strategy runs N and N-1 against one database, so schema changes must be expand/contract
  • Promotion and rollback decided by automated signals: 5xx ratio, p95 latency, business metric split by version
  • Container Apps revisions and AKS (Argo Rollouts, Flagger) give weighted traffic splitting

⏱ 30-second 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.

🗣 Full answer (senior)

How I would answer this in an interview

"All four strategies answer one question: how much of production sees the new version before you're sure it works, and how fast can you get back? Rolling deployment replaces instances a batch at a time; Kubernetes does this by default with maxSurge and maxUnavailable. It needs no extra capacity, but there's no clean cut-over: old and new serve users together, and rollback is just rolling the old image out again, which takes as long as the deploy did.

Blue-green keeps two full environments. You deploy to the idle one, test it, then switch the router. Rollback is flipping back, usually in seconds, but you pay for double capacity during the switch. On Azure App Service that's what deployment slots give you: deploy to staging, let applicationInitialization warm it up, then swap. The swap exchanges the slots' routing, so the warm instances take traffic; swapping back is the rollback. Canary is the cautious version: route 5% of requests to the new revision, compare its error rate and p95 latency with the old one, and widen to 25, 50, 100% if it's healthy. Container Apps does that with revision traffic weights; on AKS I'd use Argo Rollouts or Flagger.

The mistake I see is thinking a slot swap makes a deployment reversible on its own. It doesn't if the release dropped a column or changed a message contract: the old code you swap back to can't read the new data. So every strategy depends on expand/contract migrations: add first, migrate, switch reads, and only remove in a later release. Rollback is a property of the whole change, not of the deployment tool."


The strategies compared

Rolling Blue-green Canary App Service slots
Extra capacity Small (surge) 2× during switch Small to medium Slot shares the plan's instances
Two versions live at once Yes, mixed Briefly, or not at all Yes, by design Briefly during swap
Blast radius of a bad release Grows batch by batch Everyone at switch time Only the canary share Everyone at swap
Rollback Redeploy old version (minutes) Switch back (seconds) Set canary weight to 0 (seconds) Swap back (seconds to a minute)
Good for Stateless services on Kubernetes Big, risky releases High-traffic services with good metrics App Service web apps and APIs

Rollback per strategy

  • Rolling: kubectl rollout undo deployment/orders-api or redeploy the previous image tag.
  • Blue-green: point the load balancer, Front Door origin or DNS back at blue (DNS is slowest because of TTLs).
  • Canary: set the new revision's weight to 0 and deactivate it.
  • Slots: swap again; production gets the previous build, which is still warm in staging.

What the database must do

Change Unsafe (breaks old version) Safe (expand/contract)
Rename column sp_rename in one release Add new column, dual-write, backfill, switch reads, drop old later
Make column NOT NULL Alter in same release as code Add with default, backfill, enforce in a later release
Remove column Drop with the code change Stop using it, deploy, then drop next release
Change message contract Replace fields Add optional fields; consumers tolerate unknown fields

Production example

An API on App Service Premium v3 moved from deploying straight to production (about 40 seconds of 502s per release while the app restarted) to deploy-to-staging-and-swap with warm-up. Release-time errors dropped to zero, and a bad release in March was rolled back with a swap in 50 seconds instead of a 12-minute redeploy.

🔍 What the interviewer is checking

Checks whether the candidate understands deployment strategies as blast-radius and rollback trade-offs, and knows that database and contract compatibility decide whether rollback really works.

Green flags

  • Explains rollback for each strategy and how long it takes
  • Knows App Service slot mechanics: warm-up, sticky settings, swap back
  • Raises expand/contract migrations and N-1 compatibility unprompted
  • Mentions automated promotion signals for canaries

Red flags

  • Thinks blue-green or slots make any release instantly reversible
  • Can't describe what happens to in-flight requests or cold starts
  • Ignores the database entirely

📚 Learn in depth

1. What really happens in each strategy

Rolling (Kubernetes, maxSurge=1, maxUnavailable=0)

v1 v1 v1 v1   →   v1 v1 v1 v1 v2   →   v1 v1 v1 v2   → ... →   v2 v2 v2 v2
                  (new pod must pass readiness before an old pod is removed)

Blue-green

          ┌──► BLUE  (v1)  ◄── live
router ───┤
          └──► GREEN (v2)  ◄── deployed, tested, idle
          (switch the router; switch back to roll back)

Canary

router ── 95% ──► v1
       ──  5% ──► v2   ──► compare error rate, p95, business metric
                        └─► promote 25% → 50% → 100%   or   abort to 0%

2. App Service slots in detail

  • Slots are available on Standard and higher plans (Standard allows 5 slots, Premium allows 20). They run on the same App Service plan instances, so a heavy staging slot competes with production for CPU and memory.
  • Swap sequence: App Service applies the target slot's settings to the source slot's instances, restarts them, warms them (hitting / or the paths in applicationInitialization, and an optional custom warm-up path via WEBSITE_SWAP_WARMUP_PING_PATH), and only then switches routing. Users never hit a cold instance.
  • Slot settings (sticky): settings marked "deployment slot setting" stay with the slot, e.g. a staging connection string or ASPNETCORE_ENVIRONMENT=Staging. Everything else travels with the code.
  • Swap with preview applies production settings to staging and pauses, so you can test with production config before completing.
  • Auto swap swaps automatically after a deploy to staging succeeds (useful, but you lose the manual test step).
  • Traffic routing ("Testing in production") can send a percentage of production traffic to a slot: a basic canary.

3. Container Apps and AKS

  • Container Apps in multiple-revision mode: each deploy creates a revision; az containerapp ingress traffic set --revision-weight orders--v2=10 orders--v1=90. Labels give stable URLs to test a revision before it gets traffic.
  • AKS: the built-in Deployment is rolling only. Argo Rollouts or Flagger add blue-green and canary with automated analysis (query Prometheus or Azure Monitor and abort if error rate goes over a threshold).

4. Why two versions always coexist

Even blue-green has a window where both versions exist: background workers, queued messages written by v1 read by v2, sessions started on v1. And after rollback, v1 reads data written by v2. So the real rule is N and N-1 must both work with the current schema and message formats.

Release 1 (expand):   add column Email2 (nullable); code writes Email and Email2
Backfill job:         copy Email → Email2 in batches
Release 2 (switch):   code reads Email2, still writes both
Release 3 (contract): stop writing Email; drop Email column

Each release can be rolled back to the previous one safely.

5. Choosing promotion signals

Good canary analysis compares the canary with the baseline over the same window: HTTP 5xx ratio, p95/p99 latency, dependency failures, and one business metric (orders placed per minute). With Application Insights, tag telemetry with the revision or slot (cloud_RoleInstance, or a custom service.version resource attribute in OpenTelemetry) so you can split charts by version.

Try it yourself

  1. Create an App Service (Standard tier) with a staging slot; deploy two versions of a minimal API that returns its version, and swap while running curl in a loop. Count failed requests.
  2. Mark one app setting as a slot setting and confirm it doesn't move on swap.
  3. In Container Apps, enable multiple-revision mode and split traffic 90/10 between two revisions; verify the ratio with 200 requests.
  4. On a local kind or minikube cluster, run kubectl rollout status and kubectl rollout undo on a Deployment.
  5. Write an EF Core migration pair that renames a column with expand/contract and check that the old app version still works after the first migration.

💻 Code

Warm-up and version reporting so slot swaps and canaries can be verified (Program.cs):

using System.Reflection;
using Microsoft.Extensions.Diagnostics.HealthChecks;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddHealthChecks()
    .AddCheck<StartupWarmupCheck>("warmup", tags: ["ready"]);
builder.Services.AddSingleton<StartupWarmupCheck>();
builder.Services.AddHostedService(sp => sp.GetRequiredService<StartupWarmupCheck>());

var app = builder.Build();

var version = Assembly.GetExecutingAssembly()
    .GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "unknown";

// The swap warm-up and the canary analysis can both check which version answered.
app.MapGet("/version", () => Results.Ok(new VersionDto(version, Environment.MachineName)));
app.MapHealthChecks("/health/ready", new() { Predicate = r => r.Tags.Contains("ready") });

app.Run();

public sealed record VersionDto(string Version, string Instance);

// Reports unhealthy until caches are primed, so the swap waits for a warm instance.
public sealed class StartupWarmupCheck : BackgroundService, IHealthCheck
{
    private volatile bool _ready;

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken); // e.g. load reference data, JIT hot paths
        _ready = true;
    }

    public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken ct = default) =>
        Task.FromResult(_ready ? HealthCheckResult.Healthy() : HealthCheckResult.Unhealthy("Warming up"));
}
# App Service: deploy to staging, swap with a custom warm-up path, swap back to roll back
az webapp config appsettings set -g rg-orders-prod-aue -n app-orders-prod-aue --slot staging \
  --settings WEBSITE_SWAP_WARMUP_PING_PATH=/health/ready WEBSITE_SWAP_WARMUP_PING_STATUSES=200
az webapp deploy -g rg-orders-prod-aue -n app-orders-prod-aue --slot staging --src-path app.zip
az webapp deployment slot swap -g rg-orders-prod-aue -n app-orders-prod-aue --slot staging --target-slot production
# rollback = run the same swap again

# Container Apps canary: 10% to the new revision, then promote or abort
az containerapp ingress traffic set -g rg-orders-prod-aue -n orders-api \
  --revision-weight orders-api--v42=10 orders-api--v41=90
# Kubernetes rolling update that never drops capacity
apiVersion: apps/v1
kind: Deployment
metadata: { name: orders-api }
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate: { maxSurge: 1, maxUnavailable: 0 }
  selector: { matchLabels: { app: orders-api } }
  template:
    metadata: { labels: { app: orders-api } }
    spec:
      containers:
        - name: api
          image: contosoacr.azurecr.io/orders-api:sha-3f2c1ab
          readinessProbe: { httpGet: { path: /health/ready, port: 8080 }, periodSeconds: 5 }

⚠ Common mistakes

  • Mistake: Believing a slot swap or blue-green switch makes any release reversible. Why it is wrong: If the release made a breaking schema or contract change, the old code can't run against the new data. Instead: Use expand/contract migrations so N-1 always works.
  • Mistake: Shipping a column rename, drop or NOT NULL change in the same release as the code that needs it. Why it is wrong: During a rolling update or canary the old version is still serving and starts failing immediately; after a rollback it fails completely. Instead: Split it across releases (add, backfill, switch, drop later) and block destructive migrations in the pipeline unless explicitly approved.
  • Mistake: Running migrations after the swap or rollout. Why it is wrong: New code briefly runs against the old schema. Instead: Apply additive migrations before deploying code, and contract migrations only after the old version is gone.
  • Mistake: Deploying straight to the production slot. Why it is wrong: The app restarts cold under load, causing 502s and slow first requests. Instead: Deploy to staging, warm up, then swap.
  • Mistake: Forgetting slot-sticky settings. Why it is wrong: Staging connection strings or feature settings swap into production. Instead: Mark environment-specific settings as deployment slot settings and use swap with preview.
  • Mistake: Running heavy load tests in a staging slot on the production plan. Why it is wrong: Slots share the plan's instances, so production slows down. Instead: Load test in a separate plan or environment.
  • Mistake: Rolling updates with no readiness probe. Why it is wrong: Kubernetes sends traffic to pods that haven't started, and removes old pods too early. Instead: Add readiness probes and maxUnavailable: 0.
  • Mistake: Canary releases judged by someone glancing at a dashboard. Why it is wrong: Small regressions in 5% of traffic are easy to miss. Instead: Automate the comparison of error rate and latency between canary and baseline, with an automatic abort.
  • Mistake: Using DNS switching for blue-green with long TTLs. Why it is wrong: Clients keep hitting the old environment for minutes or hours. Instead: Switch at a load balancer, Front Door or Application Gateway.
  • Mistake: Leaving the old environment running indefinitely after blue-green. Why it is wrong: It doubles cost and drifts. Instead: Keep it for a defined rollback window, then scale it down.

🏛 Senior insight: trade-offs

I pick the cheapest strategy that limits blast radius enough for the service's risk, and I invest more in rollback-safety of the change than in the deployment mechanics. Most teams on App Service get 90% of the value from slots plus warm-up; canary pays off only when there's enough traffic for 5% to be statistically meaningful and good telemetry split by version.

None of these strategies work without observability. Before choosing one, I make sure every request and dependency call is tagged with the version (OpenTelemetry service.version, or the slot/revision name in Application Insights), that there are alerts on 5xx ratio and p95 latency per version, and that one business metric (orders per minute) is on the release dashboard. Rollback should be triggered by those signals, ideally automatically, and measured: change failure rate and time to restore (DORA). If rollbacks take longer than 5 minutes or fail because of schema changes, fix the migration practice before buying a fancier rollout tool.

What each strategy really costs

Strategy Compute cost Operational cost Risk cost
Rolling +1 surge pod/instance during rollout Low; built into Kubernetes and App Service scale-out Mixed versions; slow rollback; whole fleet affected by the end
Blue-green Up to 2× for the rollback window Two environments to keep in sync, router switch Everyone exposed at once, but instant switch back
Canary Small extra (a few replicas) Traffic splitting, per-version telemetry, analysis rules (Argo Rollouts, Flagger) Smallest blast radius; needs enough traffic to judge
App Service slots No extra instances (slots share the plan), Standard tier+ Sticky settings, warm-up config Staging load affects production; workers may run twice
Option When it fits Cost When not to
Rolling Stateless containers on AKS, low-risk changes Mixed versions, slow rollback Releases you need to cut over atomically
Blue-green High-risk releases, quick rollback needed Double capacity during switch Very large stateful environments
Canary High traffic, good metrics, many deploys a day Tooling and analysis setup Low traffic (signal is noise)
App Service slots Web apps and APIs on App Service Standard tier+, shared instances Workers that must not run twice (pause them)

🔗 Follow-ups the interviewer may ask

  1. When: Candidate says the schema must stay backward compatible during a swap. Why: Checks whether the candidate can carry out an expand/contract change in practice.
    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.

  2. When: Candidate mentions database changes during deployment. Why: Checks where migrations run relative to the slot swap or rollout.
    How to answer

    I generate migrations locally with dotnet ef migrations add, then make deployment a separate, reviewed step. The pipeline produces an artefact: either an idempotent SQL script (dotnet ef migrations script --idempotent) for a DBA to review, or a migration bundle (dotnet ef migrations bundle), a self-contained executable that applies pending migrations. That artefact runs once, before the new app version starts, with a dedicated deployment identity. I avoid Database.Migrate() at startup because several instances can race, the app needs DDL permissions it shouldn't have, and a failed migration turns into a crash loop.

🛠 Real-world problems: how you handle them

Slot swap rolled back the code but not the data
Situation
A .NET 10 orders API on App Service Premium v3 in Australia East, [about 300 requests per second at peak], deployed via staging slot and swap. A release renamed `CustomerRef` to `CustomerReference` with an EF Core migration run in the pipeline before the swap.
Signals
Immediately after swap, Application Insights showed a spike of `SqlException: Invalid column name 'CustomerRef'` from the *old* staging slot's warm-up and from background jobs; after an unrelated bug forced a swap back, 100% of order reads failed in production.
Investigation
Correlated failures by `cloud_RoleInstance` and deployment time in Application Insights; checked the migration script in the pipeline logs (`dotnet ef migrations script --idempotent`) and found `sp_rename`; confirmed with Query Store that queries referencing the old column started failing at the migration timestamp.
Resolution
Immediate: ran a hotfix migration adding a computed column `CustomerRef AS CustomerReference` so the old code could read again, then swapped back to the new version once the original bug was fixed. Long term: rewrote the change as expand/contract across three releases.
Prevention
A pipeline step that fails on destructive operations (`DropColumn`, `RenameColumn`) in migrations unless the PR is labelled `contract-phase`; an integration test that runs the previous release's test suite against the new schema; a checklist item in the PR template.

How to tell it (STAR)

**S:** We deployed our orders API through staging slots, so everyone assumed we could always swap back. **T:** A release renamed a column, and when we had to roll back for an unrelated bug, I was on call to get orders working again. **A:** I traced the errors in Application Insights to the old code reading a column that no longer existed, added a computed column with the old name as a stop-gap so the previous version worked, then led a change so destructive migrations go through expand/contract and the pipeline blocks drops and renames without a label. **R:** Orders were back within [about 20 minutes], and in the [next 12 months] we had [zero] rollbacks blocked by schema changes.

↩ Usually asked after

More in CI/CD

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me