InterviewKata
System design · Worked design D28 of 46 · Data and infrastructure · Long form

Design a deployment system

Two thousand services, fifty thousand machines, several regions, and engineers who ship thousands of times a day. Most outages start with a change (Module 04), so the system that makes changes is also the best place to stop them: release in waves, watch each wave, and undo a bad one before most users notice.

1. The prompt

"Design the internal system that deploys new versions of services across the company's fleet, safely and quickly, with automatic rollback of bad releases."

What makes it hard:

2. Frame the problem

How big is the fleet?

About 2,000 services on 50,000 machines (or containers) in 6 regions, 3 zones each.

Rollouts must be split by region and zone: those are the failure domains a bad release must not cross at once.

How often do people deploy?

About 5,000 deployments a day.

That's under one a second: the challenge is long-running, careful workflows, not request throughput.

Where does it run: VMs or Kubernetes?

Mostly Kubernetes clusters per region, some VMs.

The system should express desired state and let something on each host or cluster converge to it.

How fast must a normal change reach everywhere?

Within about a working day.

Leaves room for long bake times between waves, which catch slow-burning problems.

And an emergency fix or a rollback?

Rollback anywhere in minutes; an urgent fix in under an hour, with approval.

Two paths: the careful default and a fast path that's still staged, just with shorter bakes.

Are configuration changes deployments too?

Yes: flags, limits and rules go through the same system.

Some of the largest outages were instant global configuration pushes (Module 24).

Database schema changes?

Out of scope; teams use expand-and-contract (Module 11).

Keeps rollback safe: old and new code must both work with the schema.

Audit and approvals?

Every change recorded; some services need a second person's approval.

An append-only history of who changed what, where and when.

3. What it must do

  1. An engineer can deploy a release (an immutable artifact plus its configuration) to a service.
  2. The system rolls it out in waves, watches health, and stops and rolls back automatically when something's wrong.
  3. Anyone can see what's running where, and the full history of changes.

Not now: building artifacts (CI), schema migrations, the feature-flag system itself (we use it), cost allocation.

4. How well it must do it

TargetWhy this number
Blast radius: a bad release is stopped before it reaches more than one zone of one region surviving failuresZones and regions are the failure domains; crossing them turns an incident into an outage.
Rollback: any service back to its last good version within 5 minutes speedUndoing is the fastest fix for most incidents.
Rollout: normal changes fleet-wide within a working day; urgent fixes within an hour speed · load shapeSafety mustn't make every fix slow.
Static stability: if the deployment system is down, running services are unaffected surviving failuresThe control plane must never be on the request path.
Exact: every machine converges to precisely the intended version; every change is audited consistency · rules"What's running in production?" must have one true answer.

5. Numbers that change the design

QuantityWorking→ so we…
Deployments5,000 a day ≈ 0.06 a secondThroughput is trivial → so the design is about durable, long-running workflows and safety, not scale
Artifact trafficA 500 MB image to 2,000 machines of one big service = 1 TB per rolloutOne registry would saturate → so we use regional mirrors, layer caching and peer-to-peer distribution
Capacity during a waveReplace at most a third of a region's machines at a timeAt least two thirds stay healthy → so a bad wave never removes too much capacity
DetectionMetrics arrive every 10–60 s; a meaningful comparison needs several minutes of traffic→ so each wave bakes for minutes (canary) to hours (later waves) before the next starts

6. The nouns

releases      release_id, service, artifact_digest, config_version, created_by, created_at
deployments   deployment_id, service, release_id, strategy, status, current_wave, started_by
waves         deployment_id, n, targets, bake_minutes, gates, status (pending | rolling | baking | done | rolled_back)
desired       target_id → release_id, generation                      (written by the control plane)
actual        host_id → release_id, generation, healthy, reported_at  (written by agents)
audit         event_id, who, what, where, when                        (append-only)

7. The contract

POST /v1/services/{svc}/deployments  {release_id, strategy: "staged" | "fast"}   Idempotency-Key: …
     → 202 {deployment_id}
GET  /v1/deployments/{id}            → {status, waves: [{n, targets, status, gates}]}
POST /v1/deployments/{id}/pause | /resume | /rollback
GET  /v1/services/{svc}/versions     → [{release_id, targets, share_of_capacity}]
agent: GET /v1/targets/{target}/desired?since_generation=…   (long poll) → {release_id, generation}
agent: POST /v1/hosts/{host}/actual  {release_id, generation, healthy}

Data flow: release → deployment plan → wave n: set desired state for its targets → agents pull and switch → health gates over the bake time → next wave, or rollback → audit at every step.

8. First working version

A deployment API, a workflow that walks the waves, a desired-state store, an agent on every host, and an artifact registry.

8.1 Starting a deployment

The API checks permissions and approvals, records the release and the plan, and starts a workflow for this deployment. Only one active deployment per service at a time (a lease, Module 21), so two engineers can't fight over the same fleet.

8.2 Hosts converge

The control plane never pushes commands into hosts. It writes desired state; each host's agent (or the cluster's own controller in Kubernetes) watches it, pulls the artifact, drains, switches and reports. Repeating that is harmless: it's reconciliation, not a script.

8.3 What's running where

Agents report actual state; the API joins desired and actual per service so anyone can see versions, stragglers and failures.

Parked for laterevery target at once (9.1) · how we know a release is bad (9.2) · what if the deploy system is down (9.3) · a terabyte of images per rollout (9.4) · configuration pushes (9.5) · a crash mid-rollout (9.6).

9. Make it hold up

9.1 Waves and blast radius blast radius

ApproachWhy
✗ BadEverywhere at onceFast, and a bad release hits every user at the same moment.
~ GoodRolling batches of 10% across the fleetCapacity stays up, but a subtle problem spreads through every region before fleet-wide metrics show it.
✓ GreatStaged waves along failure domains: one canary host or cell, then one zone, then the rest of one region, then a few regions, then the rest; never two regions in the same early wave; bake between waves; replace at most a third of a region's machines at a timeA bad release is caught while small, and the waves follow the boundaries the system is designed to survive. Amazon describes the same shape, with hour-long bakes after the first stages.

9.2 Knowing a release is bad blast radius · rollback in 5 minutes

ApproachWhy
✗ BadAn engineer watches dashboardsSlow, inconsistent, and nobody watches the 4,999th deploy of the day.
~ GoodFleet-wide alarms (error rate, latency) roll back automaticallyCatches big problems, but a bug hitting 1% of capacity barely moves fleet-wide numbers.
✓ GreatAutomated canary analysis: compare the new version's hosts with old-version hosts serving the same traffic at the same time (errors, latency, crashes, CPU, key business metrics), with a statistical test; roll back automatically on a clear differenceSensitive at tiny exposure, because it compares like with like. Netflix and Google publish this approach (Kayenta; the SRE workbook's canarying chapter).

Rollback means setting desired state back to the last good release: agents converge exactly as they do for a deploy, and the previous artifact is still cached on every host, so it takes minutes.

9.3 The deploy system can fail; services can't static stability

9.4 Getting a terabyte of images to the fleet rollout speed

9.5 Configuration is a deployment too blast radius

Flags, limits, firewall rules and routing tables can break everything as fast as code, and they're often pushed globally in seconds. Send them through the same staged waves, validate them before the first wave (schema, limits, a dry run), and keep an emergency path that is still staged, just faster. Cloudflare's 2019 outage and CrowdStrike's 2024 outage were both global pushes of content rather than code (Modules 24 and 27). Feature flags then separate deploying code from releasing behaviour to users.

9.6 A rollout that survives crashes exact

A rollout lasts hours and touches thousands of hosts; the orchestrator will restart in the middle of some of them. Run each deployment as a durable workflow (Module 22): every wave's progress is recorded, so a restart resumes at the right wave instead of starting over or skipping one. Desired state carries a generation number so agents ignore stale instructions.

9.7 The whole design after the deep dives

10. Interviewer follow-ups

Rolling back isn't safe: the new version changed the database.

That's why schema changes go expand-and-contract in separate releases: the new code works with the old schema and vice versa, so rollback stays safe. When a change truly can't be undone, roll forward with a fix through the fast path.

How do you deploy the deployment system?

With a separate, simpler pipeline (or an older stable version of itself), staged by region, and with the data plane unaffected if it breaks. Never let it be the only way to fix itself.

A critical security fix must go everywhere today.

Use the fast path: same waves, much shorter bakes, a required approval, extra monitoring. Still staged: an urgent bad fix is worse than an urgent good one.

Canary analysis keeps rolling back good releases.

The comparison is too sensitive or the metrics are noisy. Tune per service: which metrics count, how big a difference matters, minimum traffic before judging. Track false rollbacks as a quality metric of the system itself.

Mobile apps can't be rolled back.

Use the app stores' phased rollouts, ship risky behaviour behind server-controlled flags, and keep the server compatible with several app versions.

A stateful service (a database cluster) needs a new version.

One replica at a time, followers first, the leader last after a controlled failover, with health checks between steps and never fewer than a quorum available.

Freeze deployments over a holiday.

A freeze window in policy: the API rejects normal deployments to listed services, the fast path stays open with extra approval.

Ten times the services.

The control plane scales easily (deployments are rare events); artifact distribution and agent long-polls scale with regional control planes and caches.

11. When things break

FailureWhat users seeHow we detect itWhat limits the damage
Bad releaseErrors for a small share of users, brieflyCanary analysis against baselineAutomatic rollback; the wave never left one zone
Control plane downNothingHealth of the deploy API and workflowsStatic stability: hosts keep running; deploys pause
Registry overloadedNothing; rollouts slowPull latency and failuresMirrors, peer-to-peer, pre-fetching
Agent bugHosts stuck on an old versionDesired vs actual driftAgents are deployed in waves too; drift alerts
Bad global configCould be everyone, at onceValidation, then canary wavesConfig goes through the same staged path
Orchestrator crash mid-rolloutNothingWorkflow heartbeatsDurable workflow resumes at the right wave

12. Wrap-up and the clock

Trade-offs we made:

What we'd watch: deployments per day and their success rate · automatic rollbacks (true and false) · time from merge to fleet-wide · desired vs actual drift · artifact pull latency · incidents caused by changes.

At 10×: more regional control planes, more artifact caching and peer-to-peer; the workflow logic stays the same.

A 60-minute interview

0–5Frame: fleet, deploy rate, rollback, config
5–10Must do, how well, the artifact and detection numbers
10–15Nouns, contract, data flow
15–25First version: deploy → desired state → agents converge
25–50Deep dives: waves (9.1), detection (9.2), static stability (9.3)
50–60Config or artifacts, follow-ups, wrap-up

A 90-minute interview

0–8Frame, including approvals and stateful services
8–15Must do, how well, numbers
15–22Nouns, contract, data flow
22–35First working version
35–75Deep dives 9.1–9.6 and the final picture
75–85Follow-ups: unsafe rollbacks, deploying the deployer, mobile
85–90Trade-offs, metrics, 10×
LevelWhat a strong answer shows
Mid-levelCanary then rolling deploys, health checks with automatic rollback, an artifact registry, a record of what's deployed.
SeniorWaves along failure domains with bakes, desired-state reconciliation, automated canary analysis against a baseline, static stability, config through the same path.
Staff+Change as the main cause of outages and the policy that follows (bakes, freezes, fast path), measuring the deploy system itself (false rollbacks, lead time), artifact distribution at fleet scale, safe rollouts of stateful systems and of the deployer itself.

Common mistakes:

13. Try it, check yourself, read more

Blast-radius simulator. One region's rollout. Pick a strategy and a bug, and watch the share of the fleet running the new version (green) and the errors users get (red). Detection needs a few minutes of data; rolling back takes 5 minutes.

Model: fleet-wide alarms fire once the extra error rate across the whole fleet exceeds 1% for 5 minutes; canary analysis compares new and old hosts directly and needs 5 minutes of data. Illustrative numbers.

Why does automated canary analysis catch bugs that fleet-wide alarms miss?

A bug on 1% of hosts barely moves fleet-wide numbers; side by side, the difference is obvious.

The deployment system's control plane goes down. What should happen to running services?

Static stability: the control plane decides, the data plane runs, independently.

How should a change to a firewall rule set reach the fleet?

Global config pushes caused some of the biggest outages on record.

What does a rollback do in a desired-state system?

The previous artifact is cached on every host, so convergence takes minutes.
ResourceWhy
Automating safe, hands-off deployments (Amazon Builders' Library)Waves, bake times and automatic rollback at Amazon.
Canarying releases (Google SRE workbook)How to compare canary and baseline, and choose metrics.
Kayenta (Netflix and Google)Open-source automated canary analysis.
Static stability using Availability Zones (Amazon Builders' Library)Why the data plane must keep working without the control plane.
Kraken and DragonflyPeer-to-peer image distribution for large fleets.
Kubernetes DeploymentsDesired state and rolling updates inside a cluster.