Systemsfor Aravinda
0 / 78 core
Week 6 · Reliability

Deploys and chaos

2 hours · core path

Read first: SLOs and error budgets

In one sitting

A deploy is a reliability control: how much traffic the new code sees before you trust it, and which measurement is allowed to stop you. Rolling, blue/green, and canary differ in blast radius and in how fast you can go back. A canary that watches CPU instead of a user-facing SLI will promote a correctness bug, and chaos is a hypothesis with an abort, not a tool name.

Shipping is how a bug reaches users, so the deploy is part of reliability, not a chore that happens after the design. The shape that matters is how much traffic the new code sees before you trust it, and which measurement is allowed to stop the rollout. A canary that watches the wrong number is a slow way to ship the bug to everyone.

Core concepts

You have four ways to put a new binary, or a new behavior, in front of people. They differ in blast radius and in what rollback actually costs.

Rolling. A few instances at a time. The load balancer drains connections on the instance you are about to restart, lets in-flight requests finish, and only then is the process replaced. Old and new overlap for the length of the roll. You do not need a second full fleet. You do need spare capacity, because the instances being restarted are not serving, and a roll that uses every last machine will brown out the site while it “succeeds.”

A rolling deploy that never stops to look is a slow big-bang. If you have 40 instances and you replace 4 every 2 minutes without reading a signal, the new code is on the whole fleet in 20 minutes. The bug arrives in slices and is global anyway. Pause between batches. Look at the user-facing SLI, not at “the process came up.” If the SLI moves, stop and put the old binary back on the instances you already switched. Mixed versions are the cost of that pause. Two versions of the service have to tolerate each other, and both have to tolerate the data either one writes.

Blue/green. Two fleets. Blue is serving. Green is the new code, up, with no user traffic, or with a synthetic check. You switch the balancer from blue to green. Rollback is switching back, which is fast when it is only a switch. You pay about twice the capacity for the overlap, and you pay a constraint on data: green must not write something blue can no longer read. If green drops a column or rewrites a row into a shape the old process rejects, the switch back fails open onto broken reads, or you cannot switch back at all. The traffic cut is the easy half. The compatible schema is the half that makes the cut reversible. Add the new shape first, deploy code that can read both, move readers, and only then delete the old shape, after no instance still needs it. A blue/green tool that does not know about that order will cheerfully switch you into a corner.

Blue/green is all-or-nothing at the moment of the switch, unless you send a slice of traffic at green first. That slice is a canary. The two ideas stack. The fleet switch is not a substitute for looking at a small population.

Canary. A slice of traffic on the new version. Watch the SLI. Then proceed, or roll back. The slice is the blast radius: 5% of instances, or 5% of requests, and you should say which. Instances and requests differ when one instance is hot. Tie the decision to a user-facing SLI from the objectives page: success and latency of the request the user made, over the canary cohort compared with the rest. A canary that does not look at that SLI is a dice roll. CPU, memory, and “the process is up” are USE clues and liveness. They are not the promise. The worked example is a bug those clues cannot see.

Stop the roll when the canary’s SLI burns faster than the baseline, or when you cannot see the SLI at all. Blindness is an abort. Promoting because the graphs are empty is how a metrics outage and a bad deploy become one incident. Give the canary a clock. A slice you watch for a few minutes will not show a bug that needs a rare path. A slice you watch for a day is a slow rollout you should have called a slow rollout. Pick the window from how often the path runs, and write it down before you start, so a flat CPU graph cannot talk you into skipping the wait.

Feature flags. Separate ship from release. The binary can roll onto every instance, dark. The new behavior turns on for employees, then for one tenant, then for a percent of users. Undo is a write to the flag, not a build and not a drain. That is faster than putting the old binary back, and it is the right undo when the bug is in the behavior rather than in the process failing to boot.

A flag is not free and it is not a test. You now have two paths. The off path rots if you leave the flag for a year, and the next person does not know which path is real. Delete the flag when the release is done. A flag also does not make a schema change safe. If turning it on writes the new shape, turning it off does not unread those writes. And a flag that wraps a bug, “skip the inventory decrement when this is on,” is a convenient way to ship the bug with a false sense that you can reverse it. You can reverse the behavior. You still needed an SLI that would notice the behavior was wrong. The flag is the brake. The SLI is the sensor. A brake without a sensor stops the car when you happen to be looking out the window.

Ship and release, said cleanly: the deploy puts code on machines. The flag, or the canary percentage, puts behavior on users. Do them as two steps when a mistake is expensive. Do them as one step only when you can see the SLI and the blast radius of “everyone” is acceptable, which is rarer than the default pipeline assumes.

A worked example

Checkout, a new binary. Assumptions, labeled:

  • 40 instances, 20 checkouts per second, steady.
  • The canary is 5% of traffic, watched for 30 minutes, then promoted if the watch looks calm.
  • The bug: a coupon path returns success and never decrements inventory. No exception. Status 200. The handler does less work than the correct one, because it skips a write.

Someone attaches the canary to CPU, because every host already has a CPU panel and the SLI dashboard is “a later project.” CPU on the canary instances stays flat. It may even fall, since a skipped write is less work, not more. Latency does not move. The error rate does not move, because nothing fails. If your user-facing SLI is only “HTTP success in under 300 ms,” it stays green too. You promoted a correctness bug with a clean conscience. The machine was fine. The ledger was not.

How many checkouts did the slice touch, and how many will the full fleet touch once you promote and nobody in finance notices until the next day?

canary requests = 0.05 * 20 / s * 30 * 60 s = 0.05 * 36,000 = 1,800
full fleet, same 30 minutes = 36,000
a day = 86,400 seconds
promoted, unnoticed for a day = 20 * 86,400 = 1,728,000 checkouts

The interview shortcut is 10^5 seconds in a day, so 20 times 10^5 is 2 million, the same order as 1,728,000. Use the shortcut in your head. The canary’s entire job was to make 1,800 the whole incident instead of 1.7 million. It did not, because the sensor cannot see a skipped write. A dice roll that happens to land on an idle CPU is still a dice roll.

The SLI that catches this compares two business facts you can count: checkouts that captured a payment, and inventory decrements for those orders. On the baseline the two move together. On the canary, payments continue and decrements fall, for the coupon path. That ratio is user-facing in the only sense that matters here. A shopper was charged and the stock was not held. “200 in under 300 ms” is a liveness SLI, and you still want it, and it is blind to this class of bug. A canary is only as good as the SLI you attach. If you cannot measure the bug, say so before the rollout and do not pretend CPU is a stand-in. Some bugs need a test that compares outputs, or a reconciliation job you watch during the canary window, not a host graph.

With that SLI on the 5%, you see the decrement ratio drop inside the 30 minutes. You stop. 1,800 checkouts are wrong, which is still a real mess and is fifty times smaller than a day on the full fleet. If the new behavior is behind a flag, undo is turning the flag off. The bad binary can stay on the box, dark, while you fix it. If you rolled the behavior in the binary itself, undo is a rollback of the 5%, draining those instances back to the old build. Both are acceptable. The flag is faster. Neither helps if you already promoted.

CPU belongs in the review after the SLI moves, as a USE clue. On this bug it would have sent you the wrong direction anyway: less work, cooler machines, a graph that argues for promoting. That is the specific failure of a resource canary on a correctness bug. It is not a straw man. It is what you get when the only dashboard in the room is the one the hosting provider opened for you.

flowchart LR
  clients[Clients]
  balancer[Load balancer]
  old[Old instances]
  canary[Canary slice]
  sli[User facing SLI]
  gate[Promote or roll back]
  clients --> balancer
  balancer --> old
  balancer --> canary
  canary --> sli --> gate

The gate reads the SLI, which for this bug is payments against decrements, not a CPU line. The old instances stay on the other 95% until the gate says promote. If the gate cannot see the SLI, it does not promote. An empty graph is not a calm graph.

A rolling version of the same bug, no canary pause: 4 instances at a time, 2 minutes each, 10 batches, 20 minutes to 100%. You never had a cohort to compare. By the time finance sees the gap you have no baseline instances left serving the old path. Blue/green is worse if you switch 100% and the sensor is CPU: the blast radius jumps in one cut. Blue/green is better if the sensor is the real SLI and you can switch back before green has rewritten data the old code cannot serve. Here the bad writes are missing decrements, which the old code can still understand. Switching back stops the bleeding and leaves you a reconciliation problem for the 1,800, or for the full fleet if you switched everyone. Rollback restores the path. It does not uncharge a card. That is an application fix, and it is cheaper on 1,800 rows than on 1.7 million.

Chaos, as a hypothesis

Chaos engineering is a hypothesis, a small blast radius, an abort condition, and a rollback you have practiced. The point is the hypothesis, not the tool that kills a process.

Write the hypothesis before you touch production. For this checkout fleet: if one instance dies, the user-facing success SLI does not move, because the balancer drains it and stops sending new work, and in-flight checkouts finish or fail inside the client timeout. That sentence can be wrong. The experiment exists to find out whether it is wrong, on a radius you can survive.

Blast radius: one instance. Not one zone, not one region, not “a random tenth of the fleet” on the first run. You are checking a single-host failure, so the fault looks like a single host. Abort: you stop if the checkout SLI’s error or latency burn crosses a line you wrote down before the start, using the same burn idea as the objective, or if you cannot see the SLI. An experiment you cannot measure is not brave. It is the canary problem again. Rollback: you know the command that stops the kill, you have run it on a quiet day, and you know how the instance comes back into the balancer. An abort you have never executed is a wish you will read off a wiki while the SLI burns.

Chaos Monkey is the Netflix tool, from the architecture they published, that killed instances in production on purpose. That sentence is about the tool in those writeups. It is not a claim about what their systems look like now, and it is not a recommendation to install something of that name. Hystrix, the breaker library from the same OSS years, is in maintenance. Do not describe either as the current architecture. The streaming writeup is where that published split, control plane in one place and video bytes in another, actually lives. What you steal from Chaos Monkey is the willingness to kill one instance against a hypothesis. What you do not steal is a product name in place of the abort condition.

A team that cannot see the user-facing SLI should not kill instances to learn. They should build the measurement first. Causing a failure you cannot detect, and cannot stop, teaches nothing except how the incident feels. The same rule stops you from running the experiment in an hour where the error budget is already burning. You would not know which fault spent the budget.

The failure mode this is aimed at is a change with no radius. Three Cloudflare postmortems are the shape, and the writeups have the detail. On 2 July 2019 a WAF rule went global without a staged rollout, CPU on the HTTP path pegged, the outage lasted 27 minutes, and customers saw 502s. The regex was the trigger. The list they published under it includes a rule that went everywhere at once and a rollback that was slow. On 17 July 2020 a backbone change meant for one city drew traffic from many cities, about 27 minutes, traffic across the network down by about half. On 21 June 2022 a prefix change hit 19 data centers, about half of requests, and engineers had trouble reaching the broken locations to undo it because the control path rode the data path they had just broken. Do not memorize the dates for their own sake. The shared design error is a global change with no blast radius, plus tools that die with the thing you need to abort. Your canary and your chaos abort are the small version of the same lesson: a slice, a sensor that is not the thing you are breaking, and a way back you have used.

flowchart LR
  idea[Hypothesis]
  radius[Small blast radius]
  watch[Abort on the SLI]
  back[Practiced rollback]
  idea --> radius --> watch --> back

You do not start at the tool and work backward. The hypothesis picks a radius that could falsify it and no more. The abort watches the same class of SLI the canary watches. The rollback is rehearsed, or it is not a step, it is a hope.

Tradeoffs

Choice Blast radius Rollback What you are pretending
Rolling, no pause, no SLI Grows to everyone on the batch clock Redeploy the old binary, after the fact That booting is the same as being correct
Rolling, pause on the user-facing SLI One batch until you continue Stop, restore that batch That mixed versions can coexist, which you have to make true
Blue/green switch Everyone, in one cut Flip the balancer back That the old fleet can still read what the new one wrote
Canary on the user-facing SLI The slice, for the window you set Stop the ramp or turn the flag off That the SLI can see the bug you are afraid of
Canary on CPU The slice, then everyone, if CPU stays calm You will not roll back, because nothing looked wrong That a correctness bug moves a host graph
Feature flag The cohort you enabled A write, not a deploy That you will delete the flag, and that the data is compatible either way
Chaos on one instance That instance Stop the kill, a command you have run That you can see the SLI and that the budget can afford the lesson

The CPU row is the worked example. Leave it in the table so it sits next to the canary row it imitates. They are not the same choice.

Pitfalls

  • A canary whose only panel is CPU or “instance healthy.” A correctness bug that returns 200 and skips a write will not heat the machine. You promote, and the ledger drifts until a person notices.
  • An SLI of HTTP success and latency, used as if it covered correctness. It covers liveness. A missing decrement, a wrong price, a swapped user id on an otherwise fast 200 will pass. Attach a signal that can fail when the business fact fails, or say you are blind and shrink the radius to something you can reconcile by hand.
  • A rolling deploy with no pause. The batch clock is the outage clock. Mixed versions last 20 minutes and then the old code is gone, taking your baseline with it.
  • Blue/green plus a migration that deletes a column the old fleet still reads. The switch back is a second outage. Expand, then contract, after the old code is actually dead.
  • A feature flag left on for a year. The off path does not boot anymore, so the flag is fake and the next rollback is a revert you cannot ship. Delete flags on purpose.
  • A flag treated as permission to skip the SLI. Undo being fast is not the same as detection being fast. You still have to notice.
  • Chaos with a radius of a zone, an abort you have not practiced, or a hypothesis of “let’s see what happens.” You will see what happens. You will not know whether it falsified anything, and you may not be able to stop it.
  • Naming Chaos Monkey as if it were a current architecture or a product you should install. It is a Netflix tool from the published writeups, and the lesson is the hypothesis.
  • An abort path that uses the system under test. You cannot reach the broken site to roll it back, because the dashboard was behind the same deploy. Measure and abort from somewhere the fault does not include.
  • Experimenting, or canarying a risky change, while the error budget is already gone. You cannot tell the new burn from the old one, and the policy was to stop spending.

In the interview

In the first five minutes, draw the path of a request through old and new, and say which fraction sees the new code. Name rolling, say you pause on the user-facing SLI, and say a flag separates the binary landing from the behavior turning on. Give the coupon bug in one sentence: CPU will not move, payments against decrements will. That is the number and the bottleneck. The bottleneck is not deploy speed. It is a sensor that cannot see the failure mode you are introducing. The honest tradeoff is blast radius against spare capacity and against mixed versions: blue/green rolls back as a switch and costs a second fleet, rolling is cheaper and easier to half-finish.

Skip the product names of your employer’s deploy system. If you mention Chaos Monkey, park it in one sentence: Netflix’s published tool that killed instances on purpose, not their current architecture, and not the answer. The answer is the hypothesis, one instance, an abort on the SLI, a rollback you have run. The question that usually follows is how you roll back a schema change, or what SLI catches a silent data bug. Compatible writes first, delete the old shape last. The SLI has to mention the business fact, not the host.

Check yourself

A canary watches CPU. The new checkout returns success and skips the inventory decrement on a coupon. Why do you promote, and which signal would have stopped you?

CPU does not rise. The bug does less work, so the host graph stays calm or improves. Status codes stay successful, and latency does not move, so a liveness SLI of fast 200s stays green too. You promote because every sensor you attached is blind to a missing write. Stop on a comparison the bug can move: paid checkouts against inventory decrements, canary versus baseline. If that ratio drops on the slice, roll back the slice. A host metric was never going to see a ledger bug.

The canary is 5 percent of 20 checkouts per second, watched for 30 minutes. How many requests does it expose, and what does a full day on the fleet cost if you promote blind?

Five percent of 20 per second for 1,800 seconds is 0.05 times 36,000, which is 1,800 checkouts. The full fleet in that half hour is 36,000. A day is 86,400 seconds, so 20 times 86,400 is 1,728,000, on the order of 20 times 10^5. The canary exists to keep the bad set near 1,800. It only does that if the SLI can see the bug and you do not promote when you are blind.

What four things does a chaos experiment include before anyone kills a process?

A hypothesis you could falsify, a small blast radius that matches the hypothesis, an abort condition on the user-facing SLI including the case where you cannot see the SLI, and a rollback you have already practiced. Killing an instance is the method, after those four. A tool name is not one of them.

What is Chaos Monkey, and what must you not claim about it?

It is the Netflix tool, described in their published architecture, that killed instances in production on purpose. You must not claim it is their current architecture, and you must not treat the name as the design. The design is the hypothesis, the radius, the abort, and the practiced rollback. Hystrix, from the same era of published client libraries, is in maintenance. The idea to keep from that era is the breaker, not the artifact.

A feature flag turns the new checkout behavior on for 5 percent of users. The binary is already on every instance. What can you undo without a deploy, and what can you not?

You can turn the behavior off with a flag write, which is faster than draining instances back to an old build. You cannot unread a schema change the new path already wrote, and you cannot detect the bug by having the flag. Detection is still the SLI. You also owe the deletion of the flag once the release sticks, or the off path rots and the next undo is fiction.

Based on: Google SRE book and SRE workbook; Netflix Chaos Monkey, published writeups; Cloudflare postmortems.