Course contents · Lesson 16 of 19

Chaos Engineering Basics: Breaking Things on Purpose

When Things Break · Lesson 16 of 19 · 10 min Engineer

Your shop's design says checkout survives losing one of its three app servers: health checks drop the dead one and the other two carry the load. Nobody has ever checked, and the first real test may come during the yearly sale. This lesson covers chaos engineering basics: how to test claims like that on purpose, in small, controlled experiments, so you find the gaps before your users do.

What chaos engineering is

Chaos engineering is running controlled experiments that inject failure into a system to learn how it really behaves. Despite the name, it is not breaking things at random: you choose one kind of failure, predict the result, watch closely and stop if users start to suffer.

Every system rests on untested assumptions: that a spare can take the load, that a timeout is set, that an alert reaches someone. Lesson 11 warned that a failover path nobody has used may fail when you need it. An experiment checks such an assumption on your schedule, with people ready, instead of at 3 a.m. during an outage.

The experiment loop

Every experiment follows the same loop. It starts with the steady state: a measurable sign that the service is behaving normally, usually an SLI from lesson 5, such as checkout's error rate or its p99 latency.

Next comes the hypothesis, a prediction that could turn out wrong: if one of the three app servers stops, checkout's error rate stays below 0.5 percent. A vague hope such as "it should be fine" cannot fail, so it teaches nothing.

Before you inject the failure, the fault you add on purpose, agree an abort limit: a number that ends the experiment at once, such as the error rate passing 2 percent. Then observe your dashboards while it runs. In the flowchart, notice that both exits from the decision end in learning: an aborted run often teaches the most.

Flowchart of a chaos experiment. Step 1, define the steady state: normal error rate and p99 latency. Step 2, form a hypothesis, for example that errors stay under 0.5 percent. Step 3, inject a small failure: one server, in a test environment first. Step 4, observe the metrics against the abort limit. Decision: still within the abort limit? Yes: run to the planned end, then learn and fix by comparing with the hypothesis. No: the limit is crossed, so stop now, abort and roll back by stopping the fault and restoring normal, then learn from it too. An arrow from learn and fix returns to step 1: the next run is a little bigger
Both exits end in learning, and the abort limit is set before anything is injected.

Learning means writing down what happened, fixing what failed and running the same experiment again to prove the fix. For a surprising result, many teams use the blameless postmortem format from lesson 14.

Limit the blast radius

The blast radius is how much of the system, and how many users, an experiment can hurt if the hypothesis is wrong. Keep it as small as you can while still learning something, and widen it only after a clean run. Three habits help:

  • Start in a test environment, such as staging, the copy of the service that has no real users.
  • In production, target one instance or a small share of traffic, never everything at once.
  • Make the experiment stop automatically when a metric crosses the abort limit, so it ends even if nobody reacts in time.

The diagram shows the rings for checkout. A pod is the smallest unit Kubernetes runs, here one copy of checkout (see Kubernetes pods). The service is all of checkout's pods, and the zone is one availability zone. Notice that each ring out puts many more users at risk.

Three concentric circles. The smallest, in green with a lightning bolt, is one pod, marked start here. Around it is one service: all checkout pods. Around that is one zone: every service in it. A list on the right says to widen only after a clean run: 0, a test environment, no real users at risk; 1, one pod in production, a few users' requests; 2, one service, everyone using checkout; 3, one zone, every service in that zone. A green card adds: at every step, auto-stop at the abort limit
Start in the smallest ring: each step outwards risks far more users.

Experienced teams do run experiments in production, which has real traffic, data and settings that a test copy lacks, but they still start small. Each one can spend error budget, so schedule experiments when the budget has room.

Four typical experiments

Good experiments copy failures that really happen. A dependency is another service that yours needs, such as a payment provider. Four common experiments:

  • Kill an instance. Stop one server or pod. Does traffic move to the others, and does something start a replacement?
  • Add latency. Delay every call to a dependency by a few seconds. Slow is often worse than down, because requests pile up waiting. Do your timeouts fire?
  • Cut a dependency. Block the network path to it. Does your service degrade gracefully, still doing its main job with less, such as showing products without reviews?
  • Fill a disk. Write files until a disk is nearly full. Does an alert fire in time, and does the app fail cleanly?

Record each run in a table like this one, whose results are illustrative. Notice the two rows where reality disagreed with the plan: each is a weakness found early, not during an outage.

Failure injectedWhat the system should doWhat actually happened
Stop 1 of 3 checkout serversHealth checks drop it; errors under 0.5%Passed: errors peaked at 0.3%
Add 3 s delay to payment callsGive up after 2 s, show "try again"No timeout set: requests piled up
Block the reviews serviceShow products without reviewsPassed: reviews hidden
Fill the database disk to 90%Disk alert fires at 80%No alert: the rule watched another disk

Game days, tools and what comes first

A game day is a planned session in which a team runs failure scenarios together, with roles assigned as in an incident. It tests people as well as software: does the page reach the on-call engineer, and do the written steps for that alert work? A later lesson covers those runbooks.

Tools make experiments repeatable. Netflix built Chaos Monkey, which shuts down random instances in production during working hours, so engineers must build services that survive it. LitmusChaos and Chaos Mesh are open-source projects of the CNCF, the Cloud Native Computing Foundation, that run experiments such as deleting a pod or adding network delay in Kubernetes.

Two things come before your first experiment. First, monitoring that shows the steady state live, as in Monitoring Fundamentals: without it you cannot see the result or know when to abort. Second, a rollback plan: a tested way to end the fault and undo its effects quickly, such as stopping the tool and restarting the instance.

Also warn the on-call engineer, so that an alert during the experiment is not mistaken for a real incident.

Check yourself

A teammate wants to switch off a random production server every afternoon, with nothing measured or agreed in advance. What is missing before this counts as chaos engineering?

A steady state, a hypothesis and an abort limit. Without them you cannot tell whether the system passed or know when to stop, so it is only breaking things.

Your hypothesis says product pages stay under 1 second when the reviews service slows down. During the experiment, their p99 latency reaches 3 seconds, still below the abort limit. Did the experiment fail?

No: the hypothesis failed, and the experiment did its job. It showed that the slow reviews call holds up the whole page, perhaps through a missing timeout, so fix that and run it again.

Checkout runs three pods in each of two zones. Someone proposes a first experiment that takes down a whole zone in production. What would you suggest instead, and why?

Kill one pod in a test environment, then one pod in production, and widen only after clean runs. A small blast radius limits the harm if the hypothesis is wrong.

Go deeper