Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 20 min · revision 1

How cascading failures happen

Follow one slow dependency as it fills worker pools, multiplies retries and pushes load onto the survivors, see why some outages outlive their trigger, and mark where each resilience pattern stops the spread.

Contentsand lesson path

What you will learn

  • Trace how a cascading failure spreads through a call graph and identify where each pattern stops it.

01. Why it matters

Large outages rarely start large. A disk slows down, one dependency starts to time out, or a deploy leaves one instance crashing. A cascading failure is what can happen next: the failure of one part makes other parts more likely to fail, and their failures feed back into the first. The Google SRE book calls this positive feedback: it is how a short slowdown in one database grows into a long outage.

This skill teaches the patterns that break that feedback: timeouts, retry budgets, idempotency keys, circuit breakers, bulkheads, load shedding and graceful degradation. Each pattern makes sense only once you can see the mechanism it interrupts, so this lesson builds that picture first: a slowdown traced through a call graph, four ways failure spreads, a model of an outage that outlives its cause, and a map of where each pattern acts.

02. From one slow dependency to a full outage

Take a small online shop. Users call an edge service, which serves the home page and the product pages. For a product page, the edge calls a catalog service, and the catalog reads the stock level from a stock database. Each service runs a fixed pool of worker threads. A request holds one worker from the moment it starts until it answers, and that includes all the time it spends waiting for the next service.

Text · the call graph used in this lesson
users --> edge (16 workers) --> catalog (16 workers) --> stock database
            |                                          (normally 10 ms)
            +--> home page: needs nothing downstream

Now the stock database slows from 10 ms to 2 s per query, perhaps because of lock contention or a failing disk. Nothing has crashed and no error has been logged. Follow the numbers, which are assumptions chosen for illustration, not measurements:

  1. The catalog receives 50 requests a second. At 10 ms per stock query it keeps about half a worker busy on average (50 × 0.01 s, from Little's law). At 2 s per query it would need 100 workers. It has 16, so all 16 are waiting on stock within about a third of a second. From then on only 8 requests a second can finish (16 workers, 2 s each), and the other 42 each second join a queue.
  2. After ten seconds the queue holds about 400 requests. At 8 a second, a new request would wait almost a minute before it even starts.
  3. The edge holds a worker for every product request while it waits for the catalog, so its 16 workers fill up the same way. Home page requests need nothing from stock, yet they now queue behind product requests in the edge's single pool, and they time out too.
  4. Users press reload and client libraries retry. Every retry is one more request holding a worker, so the queues grow even faster.

Three things stand out. The failure travelled upstream, against the direction of the calls, as resource exhaustion: no error message ever moved from the database to the edge. It reached a feature with no dependency on the database at all, because both features shared one pool of workers. And a database whose process had crashed, on a host that still answers, would have been kinder: calls would fail within milliseconds with connection refused. A host that has vanished refuses nothing, which is why connect timeouts matter too.

03. Four ways failure spreads

Most cascades combine a few of these mechanisms.

  • Resource exhaustion. Something finite runs out: worker threads, database connections, memory, file descriptors or CPU. Waiting is not free, because a waiting request still holds its resources while doing nothing useful.
  • Retry amplification. Every layer that retries multiplies the load on the layers below it. If the edge, the catalog and the database driver each make two attempts, one user request can become eight queries against a database that is already struggling. Retries help with brief, random faults and hurt during overload.
  • Load redistribution. When an instance crashes, or a load balancer removes it, its share of traffic moves to the survivors. If they were already near their limit, they slow down, and if slow instances then fail their health checks, the balancer removes them as well. Each removal makes the next one more likely. A failed zone does the same to the remaining zones.
  • Shared fate. Parts that never call each other can still fail together. A query of death, a request whose contents crash any server that handles it, spreads when retries carry it from one instance to the next. A hidden shared dependency, such as a DNS resolver, a configuration service, a logging agent that is written to synchronously, or a cache the database relies on for capacity, links services that look independent on the architecture diagram.

One cost hides inside all four: wasted work. A server that has fallen behind keeps processing requests whose callers have already given up. The CPU is busy and the dashboards show high throughput, yet almost nothing useful reaches a user. The useful part of the throughput, answers that arrive without error and in time to be used, is called goodput.

04. When the outage outlives its trigger

Sometimes you fix the original problem and the system stays down. Bronson and colleagues (HotOS 2021) named this a metastable failure: a trigger pushes the system into a bad state, and a sustaining effect, very often retries, keeps it there after the trigger has gone. Huang and colleagues (OSDI 2022) later documented 22 such incidents at 11 organisations.

The model below steps through time one second at a time. A server finishes 100 requests a second and receives 80 new ones. From second 10 to second 19 its capacity halves. Clients give up after 2 s and try again, up to three attempts in total. The server works through its queue in arrival order and, by default, also processes requests whose clients have already left. The second run adds two defences: the server skips requests older than the client timeout, and clients share a retry budget that allows a retry only while tokens remain. You will build that budget in lesson 2. Save the file and run it with Python 3.10 or newer.

Python · retry_storm.py
"""A one-second-step model of a slowdown that turns into a retry storm."""
from collections import deque

NEW_PER_S = 80        # new user requests each second
CAPACITY = 100        # requests the server finishes per second when healthy
SLOW = range(10, 20)  # seconds 10-19: capacity halves (a bad disk, a GC pause...)
TIMEOUT = 2           # the client gives up after 2 s and tries again
MAX_ATTEMPTS = 3      # first try plus 2 retries


def run(drop_expired: bool, budget: float | None) -> None:
    queue = deque()   # attempts waiting at the server, oldest first
    timers = {}       # second -> attempts whose client timeout fires then
    tokens = 10.0     # retry budget: each success earns `budget`, a retry costs 1
    print(f"drop_expired={drop_expired} budget={budget}")
    print("   t  cap  sent  served  useful  queue")
    for t in range(60):
        sent = []
        for a in timers.pop(t, []):          # attempts that timed out now
            if a["done"] or a["n"] == MAX_ATTEMPTS:
                continue
            if budget is not None:
                if tokens < 1:
                    continue                 # budget spent: fail, do not retry
                tokens -= 1
            sent.append({"t0": t, "n": a["n"] + 1, "done": False})
        sent += [{"t0": t, "n": 1, "done": False} for _ in range(NEW_PER_S)]
        for a in sent:
            queue.append(a)
            timers.setdefault(t + TIMEOUT, []).append(a)
        cap = CAPACITY // 2 if t in SLOW else CAPACITY
        served = useful = 0
        while queue and served < cap:
            a = queue.popleft()
            late = t + 1 - a["t0"] > TIMEOUT  # finishes after the client left
            if late and drop_expired:
                continue                        # skip it: nobody is waiting
            served += 1
            if not late:
                useful += 1
                a["done"] = True
                if budget is not None:
                    tokens = min(10.0, tokens + budget)
        if t % 5 == 4:
            print(f"{t:4} {cap:4} {len(sent):5} {served:7} {useful:7} {len(queue):6}")


run(drop_expired=False, budget=None)
print()
run(drop_expired=True, budget=0.1)
Terminal
python3 retry_storm.py
Expected output (the model has no randomness, so it matches exactly)
drop_expired=False budget=None
   t  cap  sent  served  useful  queue
   4  100    80      80      80      0
   9  100    80      80      80      0
  14   50   120      50      10    200
  19   50   240      50       0   1030
  24  100   240     100       0   1730
  29  100   240     100       0   2430
  34  100   240     100       0   3130
  39  100   240     100       0   3830
  44  100   240     100       0   4530
  49  100   240     100       0   5230
  54  100   240     100       0   5930
  59  100   240     100       0   6630

drop_expired=True budget=0.1
   t  cap  sent  served  useful  queue
   4  100    80      80      80      0
   9  100    80      80      80      0
  14   50    84      50      50    124
  19   50    85      50      50    120
  24  100    80      90      90      0
  29  100    80      80      80      0
  34  100    80      80      80      0
  39  100    80      80      80      0
  44  100    80      80      80      0
  49  100    80      80      80      0
  54  100    80      80      80      0
  59  100    80      80      80      0

Read the first table. During the slowdown, retries push arrivals from 80 to 240 a second, more than twice what the server can do even when healthy. At second 24 capacity is back to 100, yet useful stays at 0 for the rest of the run. Every request the server finishes has waited longer than 2 s, so its client has already retried, and the retry joins the back of a queue that only grows. The trigger lasted ten seconds; in this model the outage never ends until someone intervenes, for example by cutting traffic or turning retries off.

In the second table the slowdown still hurts, but the server spends its capacity on requests that someone is still waiting for, and retries stay at about 5% of arrivals. It is back to normal within five seconds of the trigger ending. Try each defence on its own by changing the arguments of the last run(...) call: with only the expiry check, every finished request is useful again but the backlog takes until about second 34 to clear; with only the budget, useful work returns to normal at about the same time. Real systems are messier, but the lesson carries over: to recover, remove the sustaining effect, not only the trigger.

05. Where each pattern stops the spread

Each mechanism has a pattern that interrupts it, at a particular point in the call graph.

Text · mechanisms, patterns and where they live
Mechanism                Pattern that interrupts it              Lives in
-----------------------  --------------------------------------  ------------
waiting holds workers    timeout on every call, and a deadline   the caller
                         passed down the chain
one dependency drains a  bulkhead: a separate pool or limit per  the caller
shared pool              dependency
retries multiply load    retry at one layer, retry budget,       the caller's
                         backoff with jitter                     client code
calls keep hitting a     circuit breaker: fail fast, then send   the caller
broken dependency        a few probes
more work than capacity  load shedding: reject early, drop       the callee
                         requests whose caller has left
an optional part fails   graceful degradation: cached, default   the caller
                         or partial answer
retried writes repeat    idempotency keys and deduplication      the callee

Three notes on this map. First, caller-side patterns protect a service only when its callers adopt them. A service with callers you do not control, such as a public API, needs its own protection: load shedding. Second, idempotency keys do not stop a cascade; they make the retries you allow safe, as lesson 3 shows. Third, a health check that waits in the same queue as user traffic reports an overloaded instance as dead and invites the balancer to remove it, which is load redistribution again. See health checks and draining and readiness and graceful shutdown for how to keep alive and busy apart.

06. Check your understanding

Practice check · 3 questions

Tracing a cascade

Three incidents. For each, pick the explanation that fits the evidence.

Q1. Five instances sit behind a load balancer. Each can finish 200 requests a second, and traffic is 850 requests a second. The health check is an ordinary request that waits in the same worker queue as user traffic, with a 1 s timeout. One instance crashes. What is the most likely next step?
Q2. A database was unavailable for two minutes. It is healthy again, yet the checkout service has failed almost every request for 20 minutes since. Its clients already use jittered backoff, each makes up to 4 attempts, and checkout queues requests without any limit. Which explanation fits best?
Q3. A malformed search query crashes any instance that parses it. The load balancer retries a failed request once on another instance, and the mobile app retries three times. Traffic is normal, yet within minutes all 12 instances have restarted, several times. How did the failure spread?
Practice only: not graded, not saved, not evidence.

07. Apply it

The skill's practice project starts with a three-service chain and 2 s of injected latency in the last service. Before you build it, draw it:

  1. Sketch the call graph of the chain, or of a system you work on. For every service, list its pools and queues.
  2. Pick the deepest dependency and imagine it becomes 100 times slower. Write the order in which pools fill, and which unrelated features share a pool with the slow path.
  3. Mark on the drawing where a timeout, a retry budget, a circuit breaker, a bulkhead and load shedding would each stop the spread, using the map above.

In the lab you will check these predictions against real measurements.

08. Review prompt

Without looking back, explain in your own words why a slow dependency hurts more than a dead one when callers have no timeouts. Name the four ways failure spreads and give one example of each. Then describe what makes a failure metastable, and why the fix for one is to remove the sustaining effect rather than only the trigger.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check