Load shedding and graceful degradation
When more work arrives than you can finish, drop the least important part early and cheaply, so the important part still works.
Updated since you finished it. We changed this lesson after you marked it done. Your progress is kept.
What broke
In 2019, Netflix had an outage. A sizable share of members could not play for a period of time. 1
Netflix lists many things that can overload its systems. A client bug can trigger a retry storm. A backend can be under-scaled. A deploy can be bad, or the network or cloud provider can have problems. Each of these had stopped members from playing at some point. 1
At the time, Netflix had on/off circuit breakers. It had "no progressive way to shed load". 1 So the team built one into Zuul, its API gateway. Each request gets a priority. When things go wrong, low-priority requests are dropped first. 1
In 2020, days after the change went live, a similar problem hit. It had the same potential impact as the 2019 outage. This time Zuul shed traffic until the service was healthy again, "without impacting members' ability to play at all". 1
The problem was just as serious. The difference was that the system chose what to drop.
The idea in simple words
Every server has a limit. When more work arrives than it can finish, some work will fail. You cannot avoid that. You can only choose which work fails, and how.
Without a plan, the server tries to do everything. Then nearly everything fails. With load shedding, the server rejects some requests early and finishes the rest in time.
You already know rate limiting and circuit breakers and bulkheads. The difference matters:
- A rate limit is usually a fixed quota per client. It stops one client from taking more than its share.
- Load shedding is the server protecting itself. It looks at its own state, such as CPU or requests in flight, whoever the traffic comes from.
Graceful degradation goes one step further. It cuts the work per request, for example by serving a slightly stale local copy of the data. 3
The key idea. Overload means some work will fail. Decide in advance which work that is. Drop it early, cheaply and on purpose, so the important work still finishes in time.
How it works
What overload does
Step through a server under rising load. Use Next and Back, or the ← and → keys.
- Normal day. 800 requests a second arrive. The server can finish 1,000 a second, so there is almost no queue. Every answer arrives in time: goodput is 800 a second.
- A spike: 1,500 requests a second arrive. The server still finishes only 1,000. The extra 500 wait in a queue, so each second the wait gets 0.5 seconds longer.
- After about 2 seconds, a new request will wait more than 1 second, so its caller will give up first. Soon after, every answer the server finishes is late. The server is 100% busy and finishes 1,000 requests a second, but nobody reads the answers. Goodput is close to zero.
- Now the server sheds by priority. A cheap check at the door rejects the 600 prefetch requests at once with 503. Checkout and page loads, 900 a second, fit inside capacity. The queue stays short and answers come back fast.
- Load doubles again, to 3,000 a second. The gate raises its bar and sheds most page loads too. Checkout is a small share of traffic, so it still fits, and users can still pay.
The trap is that the server looks busy and healthy. It finishes as many requests as ever. But the client has already timed out, so the work is wasted. Amazon calls the useful part goodput: requests handled without errors and fast enough to use. 2 If median latency equals the client timeout, half the requests time out, so availability is 50%. 2
The Tail latency and queueing lesson showed why queues explode near 100% busy. Load shedding is what you do about it. It lets a server "maintain its goodput". 2
Shed early and cheaply
A rejection must cost much less than real work. Amazon says early rejection "is the cheapest place to drop excess traffic". 2 So check before you parse the body, open a transaction or call another service.
Google warns that rejecting is not always cheap. For a simple memory lookup, rejecting costs almost as much as serving. 3 Shedding has limits, so you still need capacity.
A simple server-side signal is the number of requests in flight. Over a limit, return HTTP 503 to new requests. 4 Google also uses CPU and rejects by criticality as use nears a threshold. 3
Decide what to drop
Not all requests are equal. Netflix sorts its traffic into three classes: 1
- NON_CRITICAL: logs and background requests. They do not affect playback, but they are a large share of load.
- DEGRADED_EXPERIENCE: features like viewing history and pause markers. Users notice, but can still play.
- CRITICAL: if this fails, the user sees an error when they press play.
Zuul gives each request a score from 1 to 100 as its first step. 1 Under overload it drops requests below a moving threshold. A cubic curve moves the threshold slowly at first, then sharply. At 35% overload the threshold is still in the mid-90s. At 80% it reaches 50. 1
Google uses four levels: CRITICAL_PLUS, CRITICAL, SHEDDABLE_PLUS and SHEDDABLE. 3 Amazon adds useful hints. The load balancer's health check is "the most important request" a server gets. Requests that finish work already started beat requests that start new work. 2
In a shop, that could mean: payment and checkout first, product pages next, then prefetch, recommendations and batch jobs. Move batch work to a queue, so it can wait.
Here is a sketch of a server-side check. Lower classes get lower limits, so they are shed first:
LIMITS = {"critical": 200, "degraded": 150, "sheddable": 100}
def admit(req, in_flight):
if req.deadline_left_ms() <= 0:
return reject(503) # the caller has given up
if in_flight >= LIMITS[req.priority]:
return reject(503, retry_after_s=5)
return None # accept the requestDrop work nobody waits for
A request whose caller has gone is pure waste. Amazon suggests clients send a timeout hint, so the server can "drop doomed requests at little cost". 2 Google says to check the time left at each stage, before more work. 4 You met deadline propagation in Backoff, jitter and retry budgets.
Keep queues small. For steady traffic, Google suggests 50% of the thread pool size or less. 4 Amazon also caps how long a request may wait in a queue. 2
Queue order: controlled delay and adaptive LIFO
Facebook found that "many of our worst incidents" had large numbers of requests waiting in queues. 5 In 2015, Facebook described using two ideas together.
Controlled delay, a variant of the CoDel algorithm from network research. If the queue has not been empty in the last 100 ms, a new request may wait only 5 ms. Otherwise it may wait up to 100 ms. 5 Short bursts still queue, but a standing queue cannot form. Facebook found these values work well for most services, without tuning for each one. 5
Adaptive LIFO. In a long queue, the oldest request's user may have already left. So the server uses FIFO normally, then switches to LIFO when a queue starts to form. 5 The newest requests then have the best chance to finish in time.
Clients can help: adaptive throttling
A rejected request still costs the server something. So Google's clients throttle themselves. Google calls this adaptive throttling. Each client counts requests (attempts) and accepts (accepted by the backend) over the last 2 minutes. 3 Once requests passes K times accepts, the client starts rejecting some new requests locally, without sending them. The chance grows as the backend accepts less:
K = 2.0 # Google's usual choice
def reject_chance(requests, accepts):
# counts from the last 2 minutes; requests includes local rejects
return max(0.0, (requests - K * accepts) / (requests + 1))A lower K throttles harder. 3 Facebook's clients also cap requests in flight to each service and fail extra ones at once. 5
Send the right signal
Use 503 for "I am overloaded". It means a temporary overload, and the server may add Retry-After. 7 Keep 429 for a client that sent too many requests, as in the rate limiting lesson. 6
The signal must calm clients down, not cause a retry storm. When Zuul sheds, it tells devices how many retries they may make, and in what time window. 1 Google advises not to retry when many backend tasks are overloaded. Let the error go back to the caller. 3
Degrade gracefully
Shedding drops whole requests. Degradation does less work per request. Google's examples: search a smaller in-memory set instead of the disk, or use a cheaper ranking. 4 Its example service stops returning pictures and small maps when capacity runs short. 4 Other choices: serve stale cached data, as in Caching and cache stampedes. Or turn off optional features with a kill switch.
Degraded modes should rarely run. Exercise them anyway, and alert when many servers use them. 4
Test it
Amazon's rule is direct. If you have not load tested "far beyond the point where it breaks", expect the worst way of failing. 2 The ideal result: goodput levels off near full use, instead of falling. 2
Netflix also tests what users see when traffic is shed. In production experiments, a small group of users has a range of priorities throttled for 45 minutes. 1 The first run found a race condition on Android and iOS, in a low-priority request that caused playback errors. 1
Trade-offs
| Option | Protects goodput? | Cost | Use it when |
|---|---|---|---|
| No limit, unbounded FIFO queue | No Goodput falls close to zero. | Nothing until the spike. | Never for user-facing services. |
| Bounded queue, reject when full | Yes , partly. | Drops at random, not by importance. | A first, simple step. |
| In-flight limit per priority class | Yes | You must label every request and keep labels right. | Mixed traffic, like checkout and prefetch. |
| Deadline checks | Yes Removes wasted work. | Clients must send a deadline or timeout hint. | Long call chains. |
| Controlled delay + adaptive LIFO | Yes | Newer requests overtake older ones. | Server queues under bursty load. |
| Client adaptive throttling | Yes Saves the cost of rejecting. | Some requests fail without trying. | Many clients call one backend. |
| Graceful degradation | Yes Less work per request. | Users get less. Rare code paths can break. | Optional parts of a response. |
Simple rule: a small bounded queue, an in-flight limit per priority class, and deadline checks. Add degradation for optional features, and test it all with load tests.
At work: how a senior uses this
- Ask of every service: "At twice our peak, what fails first? Did we choose that?"
- Write down the priority class of each endpoint with the product owner. Payment is not the same as a recommendations widget.
- Watch goodput, not only throughput. Count requests that finished in time and without error, and tie it to your SLOs.
- Count shed requests by class and alert when critical traffic is shed.
- Load test past the breaking point before big events. Check that goodput levels off.
- Review client retry rules. They should honor
Retry-Afterand stop when most calls fail.
With AI
What to ask the agent
"Add an admission check to this service. Count requests in flight. Read a priority from the X-Priority header (critical, degraded, sheddable). Reject over a per-class limit with 503 and Retry-After, before parsing the body."
"Propagate the client deadline through every call in this handler. Before each downstream call, drop the request if less than 50 ms is left."
"Write a load test that ramps from 50% to 300% of measured capacity. Plot throughput, goodput and p99 latency per priority class."
What to check yourself
- The rejection happens before any expensive work: no body parsing, database call or downstream call.
- Shed requests get 503, and the client code honors
Retry-After. - Health checks are never shed.
- Every endpoint has a priority, and unknown traffic gets a low class, not critical.
- The load test shows checkout latency staying flat while low-priority traffic is shed.
Check yourself
Your progress is saved only in this browser. Export it to keep it safe.
You have finished 5 lessons. Your progress lives only in this browser. Export a copy so you don’t lose it.
Go deeper
Show 7 sources and related lessons
- Manuel Correa, Arthur Gonigberg and Daniel West, “Keeping Netflix Reliable Using Prioritized Load Shedding”, Netflix TechBlog, 2 November 2020 (opens in a new tab)
Netflix's three request classes, the priority score in the Zuul gateway, the cubic shedding curve, and how they test it in production. - David Yanacek, “Using load shedding to avoid overload”, Amazon Builders' Library (now AWS Builder Center), 2019 (opens in a new tab)
Goodput, why a timed-out request is wasted work, timeout hints, and how Amazon load tests past the breaking point. - Alejandro Forero Cuervo, “Handling Overload”, Site Reliability Engineering (Google, O'Reilly 2016), chapter 21 (opens in a new tab)
Criticality classes, client-side adaptive throttling with its formula, and when not to retry. - Mike Ulrich, “Addressing Cascading Failures”, Site Reliability Engineering (Google, O'Reilly 2016), chapter 22 (opens in a new tab)
Load shedding versus graceful degradation, queue sizes, deadlines, and load testing until things break. - Ben Maurer, “Fail at Scale”, ACM Queue, volume 13, issue 8, 2015 (opens in a new tab)
Facebook's controlled delay queue, adaptive LIFO and client-side concurrency limits, each in a few paragraphs. - Nottingham and Fielding, RFC 6585: Additional HTTP Status Codes (IETF, 2012), section 4 (opens in a new tab)
The definition of 429 Too Many Requests. - Fielding, Nottingham and Reschke, RFC 9110: HTTP Semantics (IETF, 2022), section 15.6.4 (opens in a new tab)
The definition of 503 Service Unavailable and its link to Retry-After.
Case studies: Amazon: Why queue backlogs can turn a short outage into a long one · Netflix: Adaptive concurrency limits instead of hand-tuned limits · Shopify: Surviving flash sales with a checkout queue at the load balancer · Stripe: Two rate limiters and two load shedders that protect an API
Related: Rate limiting · Circuit breakers, bulkheads and fallbacks · Backoff, jitter and retry budgets · Tail latency and queueing · Caching and cache stampedes · Queues vs logs and delivery guarantees · Observability, SLOs and error budgets