Skip to content

Overload, backpressure and load shedding

A system is overloaded when work arrives faster than it can do it. Nothing needs to be broken: the API of the shop serves 1,200 requests a second, and a campaign, a news story or a client bug sends 9,000. The excess does not go anywhere on its own. It waits in a queue, or it is refused, or it times out.

The arithmetic is blunt. If 9,000 arrive and 1,200 can be served, at most 1,200 ÷ 9,000, which is 13% of the requests, can succeed, and 87% cannot. No setting changes that. What settings change is which requests are the 13%, how long they wait, and how much of the capacity is spent on requests whose clients have already left.

The last lesson showed the cost of that waste. Google’s chapter on handling overload states the goal: a server under overload should keep accepting as much traffic as it can, and only accept more as capacity frees up. There are three ways to answer an overload.

  1. Add capacity. More instances, more connections. It works if the overload is smaller than what you can add, and it takes time and money.
  2. Refuse work at the door. This is load shedding: the server rejects the excess early so that it can focus on the requests it lets in. Google describes it, and Amazon’s engineers give the reason: a request that waits too long is a request whose client may have gone, and the work spent on it is wasted.
  3. Tell the senders to slow down. This is backpressure, which the messaging module met on a queue: a bounded queue refuses, and the refusal slows the producers. Google’s version for services is adaptive throttling, where a client watches how many of its requests are rejected and sends fewer.

Mental model. Capacity decides how much work succeeds. Shedding and backpressure decide which work, and what the work that fails costs on the way. Only adding capacity raises the number.

Write down which component you expect to give way first. Then press Add 10x traffic and read the chain. The traffic jumps from 900 to 9,000 requests a second at one instant and stays there.

Add 10x traffic

The shop serves 900 requests a second. A campaign, a news story or a bug in a client multiplies the traffic by ten: 9,000 requests a second against an API that can serve 1,200. You add the traffic and watch where the system gives way. Then choose how to answer it, and notice what gives way next.

The failure lab needs JavaScript. The healthy system is shown below.

1. Break it

The healthy system is shown first. When you press the button the failure strikes, and the run follows the 30 seconds after it.

What the failure does: Traffic jumps to ten times what the system normally serves.

0.3 ms0.2 ms0.5 ms0.5 msClientsHealthy<1%Load balancerHealthy<1%APIBusy75%CacheHealthy1%DatabaseHealthy20%
0.3 ms0.2 ms0.5 ms0.5 msClientsHealthy<1%Load balancerHealthy<1%APIBusy75%CacheHealthy1%DatabaseHealthy20%

Each dot stands for many requests. The numbers show the real rate.

No bottleneck: every component has headroom.

0 ms

Cause and effect

Each step leads to the next. A step that is changing right now is marked.

Metrics
ComponentStateUtilisationOffered (req/s)Served (req/s)Rejected (req/s)p50p95p99
ClientsHealthy<1%90090000 ms0 ms0 ms
Load balancerHealthy<1%90090000.03 ms0.15 ms0.23 ms
APIBusy75%900900014 ms60 ms93 ms
CacheHealthy1%81081000.14 ms0.6 ms0.92 ms
DatabaseHealthy20%25225205.5 ms24 ms37 ms
Traffic
900 req/s
Successful
900 req/s
Error rate
0%
Mean latency
24 ms

Illustrative values, not benchmarks of any real product.

Model notes

Assumptions

  • Requests arrive at random, as a Poisson process, at a constant average rate.
  • Each node is one queue, served first-come first-served by several identical slots (instances × concurrency).
  • Service times are random with the stated mean; by default they are exponentially distributed.
  • Each node is analysed separately, with the traffic it receives treated as Poisson.
  • The system starts healthy at 900 requests a second. Three API instances can serve 1,200 a second and the database about 1,250 operations a second. Nine in ten requests read through the cache, which answers four in five of those reads; the rest, and every write, go to the database.
  • A failure strikes at one instant and nothing repairs it during the run: no restart, no autoscaling, no operator. The load balancer notices a dead instance at once.
  • The instances of a component are identical, and each request is independent of the others.

Simplifications

  • The traffic jumps to ten times at one instant and stays there. Real traffic ramps up, and autoscaling, which is not modelled, reacts to a ramp. The model shows what happens if nothing reacts.
  • Every request costs the same. In practice a flood often arrives as a different mix of requests, such as many more reads than writes.
  • A retry is a fresh, independent attempt with the same chance of failing as the last one. How long a real client library waits between attempts (backoff, jitter), and any retry budget or circuit breaker, are not simulated: attempts are counted, not scheduled.
  • A client gives up when its first timeout runs out, so the latency shown stops at what a client would wait: the timeout of the first hop, times its attempts. After that the request counts as a failure.
  • The cache's hit ratio is constant. Warming, stampedes and hot keys have their own labs.
  • Nothing here models garbage collection, connection pools on the client, DNS, TLS handshakes, CPU throttling, noisy neighbours or cold caches. A real system fails in more ways, and in messier ones, than this model does.
  • Above capacity there is no steady state. The model switches to a fluid approximation: the node serves at capacity, its queue grows until it reaches its limit, and further requests are rejected.
  • Percentiles assume an exponential tail. A service-time variability other than exponential changes the mean wait but not the shape of the tail.
  • A node frees its slot as soon as it has done its own work, before waiting on the services it calls. Real thread-per-request servers hold the slot, so a slow dependency exhausts them faster than this model shows.
  • A request calls its dependencies one after another. Parallel fan-out is not modelled.
  • When a caller times out and gives up, the callee still finishes the work, so abandoned requests keep consuming capacity.
  • Retries add load. Their backoff and jitter decide when that load arrives, which only the per-request simulation shows.
  • A caller’s timeout counts the mean time its dependencies take, not their full distribution.
  • Latency percentiles for a whole request are estimated, over every request, including those that are rejected and fail quickly. The mean is exact, and the percentiles come from a gamma distribution that has that mean and the variance of the time spent in each component.

Parameter values are illustrative. They are not benchmarks of any real product.

The first run: utilisation of the API goes from 75% to 750%, which is 9,000 ÷ 1,200, and the queue fills at once. On average 83% of the requests fail over the 30 seconds. The failures start lower and settle at 87%, the 1 − 1,200 ÷ 9,000 computed above.

Now choose changes, one at a time first, and press Run the same failure again with these changes.

  • Run thirty API instances. The API can serve 12,000 a second, and the failures fall from 83% to 12%. But the busiest component is now the database, at 345% of its capacity, and the retries to it multiply the attempts by 1.7. The bottleneck moved. The database was sized for a tenth of this traffic: it receives about 2,500 queries a second, the 28% of 9,000 that the cache cannot answer, and with 10 connections of 8 ms it serves 10 ÷ 0.008, which is 1,250.
  • Give the database three times the connections. Alone, this changes nothing: 83% still fail, because the API is still the bottleneck. The database could serve 30 ÷ 0.008, which is 3,750, and nobody asks it yet.
  • Both together: 0% fail and the p99 is 96 ms. Capacity had to grow along the whole path, and the price is thirty API instances all the time, for a peak that may last an hour. This model has no autoscaling, and the autoscaling lesson shows why a real policy would not have been ready either.
  • Shed load: drop requests that waited too long. The failures stay at 83%, because shedding adds no capacity. What changes is what the survivors experience: the worst p99 falls from 1 s to 374 ms and the longest queue from 1,000 to 240 requests. The 17% that succeed are served quickly, and the API spends its time on requests that are still wanted.

That last result is the point. Shedding did not help the failure count here, and in the previous lesson it took the failures from 71% to 10%. The difference is the size of the overload. At 113% of capacity a deadline recovers the capacity that a growing queue wasted. At 750% almost everything has to be refused whatever you do, and shedding can only make the refusals fast and the successes timely.

The lab sheds by waiting time: a request that would wait more than 200 ms is dropped. It cannot tell a payment from a page view, and it counts both as one request. Real systems do tell them apart. Google classifies requests into criticality tiers, from critical, for the traffic users depend on, to sheddable, for the batch work that can wait or be retried, and during overload the lower tiers are rejected first. Google also describes serving degraded responses, with less data or less accuracy, as the alternative to an error.

Shedding has its own risks. Amazon lists them: a trigger that is too sensitive refuses work the server could have done, and shedding can stop an autoscaler from seeing the load that would make it scale. Queues in the load balancer or the operating system can hide how long clients are really waiting, which makes shedding react late. A shed policy is a decision about who gets hurt, and the people who own the business should make it, not a default.

  • Overload is more work than capacity. At 9,000 requests a second against 1,200, at most 13% can succeed and 87% cannot, whatever you configure.
  • Three answers: add capacity, shed load at the door, and use backpressure to slow the senders. Only the first raises how much succeeds.
  • In the lab, 83% of the requests fail on average. Thirty API instances take it to 12% and move the bottleneck to the database, at 345%. Thirty instances plus three times the database connections take it to 0%.
  • A deadline leaves the failures at 83% and cuts the worst p99 from 1 s to 374 ms and the longest queue from 1,000 to 240. In the 113% overload of the last lesson, the same fix took the failures from 71% to 10%.
  • Shedding is a choice of who is refused. It has false positives, it can hide load from an autoscaler, and it needs priorities that the business sets.

Next: dependency failures, when the thing you call is the one that breaks.

Your progress

Built by GhaziAlibi.

© ShardCraft. All rights reserved.