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:
- Speed and safety pull in opposite directions. Waiting longer between steps catches more problems and delays every fix.
- "Bad" has to be detected by a machine, from noisy metrics, within minutes.
- The deployment system can become the outage: one global push of a bad change, or a control plane failure that stops services.
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
- An engineer can deploy a release (an immutable artifact plus its configuration) to a service.
- The system rolls it out in waves, watches health, and stops and rolls back automatically when something's wrong.
- 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
| Target | Why this number |
|---|---|
| Blast radius: a bad release is stopped before it reaches more than one zone of one region surviving failures | Zones 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 speed | Undoing is the fastest fix for most incidents. |
| Rollout: normal changes fleet-wide within a working day; urgent fixes within an hour speed · load shape | Safety mustn't make every fix slow. |
| Static stability: if the deployment system is down, running services are unaffected surviving failures | The 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
| Quantity | Working | → so we… |
|---|---|---|
| Deployments | 5,000 a day ≈ 0.06 a second | Throughput is trivial → so the design is about durable, long-running workflows and safety, not scale |
| Artifact traffic | A 500 MB image to 2,000 machines of one big service = 1 TB per rollout | One registry would saturate → so we use regional mirrors, layer caching and peer-to-peer distribution |
| Capacity during a wave | Replace at most a third of a region's machines at a time | At least two thirds stay healthy → so a bad wave never removes too much capacity |
| Detection | Metrics 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
- Service and its targets (clusters, zones, regions).
- Release: an immutable artifact (by content digest) plus a configuration version.
- Deployment: a plan of waves, each with targets, a bake time and health gates.
- Desired state per target, and the actual state agents report.
- Audit event.
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.
9. Make it hold up
9.1 Waves and blast radius blast radius
| Approach | Why | |
|---|---|---|
| ✗ Bad | Everywhere at once | Fast, and a bad release hits every user at the same moment. |
| ~ Good | Rolling batches of 10% across the fleet | Capacity stays up, but a subtle problem spreads through every region before fleet-wide metrics show it. |
| ✓ Great | Staged 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 time | A 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
| Approach | Why | |
|---|---|---|
| ✗ Bad | An engineer watches dashboards | Slow, inconsistent, and nobody watches the 4,999th deploy of the day. |
| ~ Good | Fleet-wide alarms (error rate, latency) roll back automatically | Catches big problems, but a bug hitting 1% of capacity barely moves fleet-wide numbers. |
| ✓ Great | Automated 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 difference | Sensitive 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
- Control plane vs data plane: the deployment system decides; hosts and clusters run. If the control plane is down, agents keep the last desired state and services carry on (AWS calls this static stability).
- Agents cache desired state and the current and previous artifacts locally.
- Regional control planes, so a fault in one region's deploy tooling doesn't affect others.
9.4 Getting a terabyte of images to the fleet rollout speed
- Content-addressed layers: hosts download only layers they don't have, so a small code change moves a small layer.
- Regional registry mirrors and a cache per cluster.
- Peer-to-peer distribution for big fleets: hosts share pieces with each other instead of all pulling from the registry (Uber's Kraken, Dragonfly).
- Pre-fetch the next wave's artifact during the current wave's bake.
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
| Failure | What users see | How we detect it | What limits the damage |
|---|---|---|---|
| Bad release | Errors for a small share of users, briefly | Canary analysis against baseline | Automatic rollback; the wave never left one zone |
| Control plane down | Nothing | Health of the deploy API and workflows | Static stability: hosts keep running; deploys pause |
| Registry overloaded | Nothing; rollouts slow | Pull latency and failures | Mirrors, peer-to-peer, pre-fetching |
| Agent bug | Hosts stuck on an old version | Desired vs actual drift | Agents are deployed in waves too; drift alerts |
| Bad global config | Could be everyone, at once | Validation, then canary waves | Config goes through the same staged path |
| Orchestrator crash mid-rollout | Nothing | Workflow heartbeats | Durable workflow resumes at the right wave |
12. Wrap-up and the clock
Trade-offs we made:
- Slower, staged rollouts with bakes, in exchange for small blast radius.
- Desired state and reconciliation instead of push scripts.
- Automated canary analysis, accepting occasional false rollbacks.
- Configuration treated exactly like code.
- A control plane that's never on the request path.
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–5 | Frame: fleet, deploy rate, rollback, config |
| 5–10 | Must do, how well, the artifact and detection numbers |
| 10–15 | Nouns, contract, data flow |
| 15–25 | First version: deploy → desired state → agents converge |
| 25–50 | Deep dives: waves (9.1), detection (9.2), static stability (9.3) |
| 50–60 | Config or artifacts, follow-ups, wrap-up |
A 90-minute interview
| 0–8 | Frame, including approvals and stateful services |
| 8–15 | Must do, how well, numbers |
| 15–22 | Nouns, contract, data flow |
| 22–35 | First working version |
| 35–75 | Deep dives 9.1–9.6 and the final picture |
| 75–85 | Follow-ups: unsafe rollbacks, deploying the deployer, mobile |
| 85–90 | Trade-offs, metrics, 10× |
| Level | What a strong answer shows |
|---|---|
| Mid-level | Canary then rolling deploys, health checks with automatic rollback, an artifact registry, a record of what's deployed. |
| Senior | Waves 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:
- A script that SSHes into machines.
- Deploying all regions at once "because it's urgent".
- Fleet-wide alarms as the only detection.
- Control plane on the request path.
- Treating config as safe.
- No answer for rollbacks after schema changes.
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?
The deployment system's control plane goes down. What should happen to running services?
How should a change to a firewall rule set reach the fleet?
What does a rollback do in a desired-state system?
| Resource | Why |
|---|---|
| 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 Dragonfly | Peer-to-peer image distribution for large fleets. |
| Kubernetes Deployments | Desired state and rolling updates inside a cluster. |