System Design

Patterns

Graceful Degradation

Deciding which part of the answer is optional costs nothing in a design review and is impossible during an incident. Systems that degrade well are systems where somebody wrote the list down beforehand.

The shape

A service you depend on is down, slow, or returning old data. You have two options. You can fail the whole request, or you can return an answer with a part missing. Returning the smaller answer is graceful degradation, and it only works if you decided beforehand which part can go missing.

The decision is cheap before the incident and impossible during it. That gap is why this is a pattern you plan for, not something you work out during the incident. At 3am, with a dashboard full of red, nobody is going to work out that "the recommendation carousel is optional but the price is not." That decision has to be in the code already, made in a design review by somebody who had time to think.

Many decisions look different on the surface and are the same decision underneath. You choose which reads may be stale, and by how much. You choose which parts of a page are allowed to be missing. You choose to fall back to a local rate limit when the shared counter store is unreachable. You choose which operations may go ahead during a network partition, when some machines cannot reach the others. You choose to serve an expired cache entry rather than nothing. All five ask one question: which part of this answer is optional?

The ladder

Degradation is not all or nothing. There is a series of things you can give up, one after another. The useful habit is to write them down in order, from the best answer to the worst. That ordered list is the ladder, and writing it down is the design.

Eight answers, from best to worst
Each step down gives up a little more than the step above it, as the right-hand column of each box says. Every system has the green step at the top and the red step at the bottom. The six steps in the purple dashed box exist only if somebody named the optional part in a design review, before the incident.Each step down gives up a little more than the step above it, as the right-hand column of each box says. Every system has the green step at the top and the red step at the bottom. The six steps in the purple dashed box exist only if somebody named the optional part in a design review, before the incident.
Most systems build only the first and the last. Each step down gives up a little more than the step above it, as the right-hand column of each box says. Every system has the green step at the top and the red step at the bottom. The six steps in the purple dashed box exist only if somebody named the optional part in a design review, before the incident.

Most systems build only the first step and the last one. So a single late dependency takes the whole request from a perfect answer to no answer. Users would have accepted any of the six answers in between. None of them exists, because nobody built them.

Where the parts come from

There are four places to find a part you can give up. They are listed roughly in order of how often each one is the right answer.

Optional sections. A page has a required core and a set of extras, such as recommendations, related items, activity counts and personalisation. Each service that supplies an extra is a contributor, and each contributor gets a deadline. If a contributor misses its deadline, the page drops its section instead of waiting for it. This source is worth the most, because the page now takes as long as the core takes, not as long as the slowest contributor.

A deadline for every extra
Each extra gets 50 ms, marked by the purple line. Recommendations, related items and activity counts finish inside it. Personalisation is still running at 50 ms, so its section is dropped (1). The core has no deadline, because the page cannot go out without it. So the page goes out when the core finishes, at 60 ms instead of 180 ms (2).Each extra gets 50 ms, marked by the purple line. Recommendations, related items and activity counts finish inside it. Personalisation is still running at 50 ms, so its section is dropped (1). The core has no deadline, because the page cannot go out without it. So the page goes out when the core finishes, at 60 ms instead of 180 ms (2).
The page goes out when the core is ready. Each extra gets 50 ms, marked by the purple line. Recommendations, related items and activity counts finish inside it. Personalisation is still running at 50 ms, so its section is dropped (1). The core has no deadline, because the page cannot go out without it. So the page goes out when the core finishes, at 60 ms instead of 180 ms (2).

Stale instead of absent. An expired cache entry is almost always better than an error. You serve it, mark it as old, and refresh it in the background. This needs a second timeout, and it is the setting people forget. The TTL (time to live) says when an entry counts as expired. The second timeout says when an entry is too old to serve at all. It is a different number from the TTL, and it should be much larger.

Approximate instead of exact. Counts, rankings, recommendations and quota checks can usually live with an approximate answer. A rate limiter that has lost its shared data store can fall back to a limit per instance, where each server counts only its own traffic. Added up across all the servers, that limit is wrong. It is still much better than failing open, which lets every request through, or failing closed, which rejects every request.

Local instead of shared. When a shared dependency is unreachable, there is often a local copy or estimate of it to use instead. Examples are each instance's own view, a snapshot shipped with the code, or the last-known-good config, the most recent one that worked. The fallback is worse, but it is there.

The rule that prevents cascades

One form of degradation is not about answers. It belongs here because getting it wrong turns a small failure into an outage.

A component at its capacity limit should shed or spill, not die. Shedding means rejecting the extra requests cheaply. Spilling means passing them on to the next node. This matters most in a tier where each request goes to a node chosen by its key, such as a cache ring, a sharded store, or a service routed by consistent hashing. In those tiers, a node that dies does not take its load away with it. The load moves onto a neighbour. The neighbour is now more likely to die, and if it does, it passes even more load to the next node. That chain is a cascade. So at its ceiling, a node should reject cheaply, spill to the next node, or serve something degraded. It should not fall over.

Dying at the ceiling versus shedding
Every node normally runs at 70 percent of its capacity. The blue bars are load the node can serve, the red parts are load past its capacity, and the black tick is 100 percent. In the top row, a hot key sends node A 130 percent and it dies (1). Its load moves to node B, which reaches 200 percent and dies too. Node C reaches 270 percent and dies, and node D is next. In the bottom row, node A serves up to its capacity and rejects the extra 30 percent cheaply (2), so every node stays up.Every node normally runs at 70 percent of its capacity. The blue bars are load the node can serve, the red parts are load past its capacity, and the black tick is 100 percent. In the top row, a hot key sends node A 130 percent and it dies (1). Its load moves to node B, which reaches 200 percent and dies too. Node C reaches 270 percent and dies, and node D is next. In the bottom row, node A serves up to its capacity and rejects the extra 30 percent cheaply (2), so every node stays up.
A dead node passes its load on; a shedding node keeps it. Every node normally runs at 70 percent of its capacity. The blue bars are load the node can serve, the red parts are load past its capacity, and the black tick is 100 percent. In the top row, a hot key sends node A 130 percent and it dies (1). Its load moves to node B, which reaches 200 percent and dies too. Node C reaches 270 percent and dies, and node D is next. In the bottom row, node A serves up to its capacity and rejects the extra 30 percent cheaply (2), so every node stays up.

The same thinking applies to a replica that has fallen behind. If its health check passes, a lagging replica will keep serving data from 40 minutes ago. The health check asks whether the process is alive, not whether its data is current. Liveness and correctness are different questions. A read pool should remove a replica automatically once it falls further behind than a set threshold. Nobody should have to make that call by hand during an incident.

Back of envelopeWhy a deadline beats waiting, on a page with contributors
A page assembled from 1 core call and 4 optional contributors,
each independently slow (above its p99) 1% of the time.

Wait for everyone
  P(at least one is slow)   1 − 0.99^5        = 4.9%
  → ~1 request in 20 is as slow as the worst
    of 5 services

Drop any contributor past a 50 ms deadline
  P(the page is slow)       = P(the CORE is slow)
                            = 1.0%
  → the page's latency is now the core's latency

  ─────────────────────────────────────────────────────
  4.9% → 1.0%, and the cost is that about 4 percent of
  page views are missing one optional section.

The question is not technical. It is whether a missing
recommendation strip is worse than a page that takes
2 seconds, and product owns that answer.

How to tell you need this

Here is the symptom. If a page calls 6 services and every one of them has to succeed, the page's availability is the product of all six, not close to any one of them. Say each of the 6 services is up 99.9 percent of the time. The chance that all 6 are up at once is 0.999^6, about 99.4 percent. So the page is less reliable than any single service it depends on.

In a design review, the check is simpler. Pick a dependency by name, ask what happens if it returns nothing, and see whether the answer is specific. "It would fail" is honest. "It would fail, and that is correct because the data is required" is a decision. "I am not sure" means the ladder has only its first and last steps.

What it costs

This pattern has three costs. In order, they are a second code path, degraded answers that nobody can tell are degraded, and the operations that must never degrade at all.

Every degraded mode is a second code path. That means a second set of behaviours to test, monitor and reason about. Two working paths are more than twice the work of one, because you also own the switch from one path to the other.

Degraded answers need to be visible. If they are not, you will serve them for months without anyone noticing. A stale answer with no timestamp, or a partial page that does not show a section is missing, leads to support tickets nobody can reproduce. Emit a metric for each degraded mode, and alert on how often each one is used, not only on the errors it replaced.

The third cost is that some things must never degrade. Examples are a balance check before a withdrawal, an authorisation decision and a payment. Naming those is as much a part of this pattern as naming the optional parts. A design that degrades everything is as badly thought through as one that degrades nothing.

Where it shows up in the course

articlethe form it takes there
Auth: Sessions, JWT and OAuthwhen renewing a session fails, the gateway lets an identity it already checked through, but never one it has not checked
Caching Strategies and Invalidationwhat the backend does when the cache disappears and it meets 100x its normal load
CAP and What It Actually Constrainsdeciding in advance which operations may proceed during a partition
Capacity Planning and Autoscalinga fleet below its full reserve runs past its knee until new instances arrive, so decide beforehand what it drops in those minutes
CDNs and Edge Computean edge region failing over and sending its full miss traffic at the origin at once
Circuit Breakers, Bulkheads and Backpressurethe whole family, derived from Little's Law, and what to serve when a breaker is open or a request is shed
Consistency Modelsdeciding which reads may be stale, and by how much
Consistent Hashingshedding at the ceiling instead of dying, so one hot key cannot cascade
Deployments: Blue-Green and Canarya kill switch is a degraded mode decided in advance: the flag turns a listed feature off under load without a deploy
Design a Distributed Job Schedulerwhen a pool runs short, windowed runs wait inside their windows and strict runs go first
Design a Distributed Message Queuea partition below its in-sync minimum refuses acks=all writes with a retryable error and keeps serving reads
Design a Leaderboard / Ranking Servicewith Redis down, matches are still recorded, responses leave out the rank, and the edge serves a stale top 100
Design a Payment Systemnew payments fail over to a second processor or wait; an unknown call is resolved only where it was sent, with its own key
Design an Ad Click Aggregatorwhen the stream job is down, clicks are still recorded and the counts go stale with their age shown
Design Google Docs (Collaborative Editing)cursors are the optional part of a shared session: an overloaded owner stops passing them on and keeps numbering edits
Design Yelp (Nearby Places)search, place pages and photos keep serving from each region's copies; only posting a review or a photo, or editing a place, fails, with a retryable error
Distributed Cachea gutter pool decides in advance what a dead node costs: values up to a minute stale, and part of its reads reaching the databases
Distributed Rate Limiterfailing open to a local limit rather than to unlimited, so the fallback is a worse answer and not no answer
Dropbox and Google Drivewithout hints devices list on a timer, and sync slows from seconds to minutes instead of stopping
Instagramshedding full-size image requests while thumbnails keep serving
Key-Value Storea partition without a leader keeps serving eventual reads while its writes fail with a retryable error
Latency Numbers That Matterreturning a partial answer when a contributor misses its deadline
Load Balancingwhat a balancer does when every backend is failing health checks, where the obvious answer makes it worse
Multi-Region and Disaster Recoverymoving a failed region's users into a cold cache is a planned overload, so decide in advance what the surviving region stops doing
Notification Servicethe type registry decides in advance: campaigns wait or drop, sign-in codes use the reserved quota or the second provider
Observability: Metrics, Logs and Tracestelemetry is the optional part of every request: DEBUG lines and sampled successes drop first, error lines and SLI counters never
Push Notification Deliverydeciding in advance which pushes wait when the provider throttles you: promotions wait, sign-in codes go first
Replication and Leader Electionejecting a lagging replica from the read pool on a staleness threshold
Search Autocompletepersonal and trending suggestions drop first, then freshness, then all suggestions, and none of them ever blocks the search
Security in System Designa protective check degrades to a weaker check, such as a local rate limit, and never to no check
Ticketmaster Bookingthe waiting line is the degraded mode: when checkout struggles, a new buyer waits longer instead of getting an error
Uber Ride-Hailingthe map, surge and match quality may degrade; the claim, the accept, the quoted price and the charge may not
Web CrawlerDNS, uploads and slow sites may wait; politeness and robots.txt never degrade
WebSockets, SSE and Pollingeach transport as the fallback for the one above it, down to plain polling when the push tier is out
WhatsApp and Chat Systemspresence, typing and receipt counts as the optional parts, shed under load so message delivery stays whole
YouTubeshedding renditions under transcode backlog, so a video is available at 480p rather than not at all
Live Comments and Reactionsunder load the comment cap, the batch window and the reaction totals shrink first; removals and the archive never do

Getting it wrong

Having only two steps on the ladder. The system returns either the full answer or an error. Every answer in between has to be built on purpose. If none exists, every dependency is in effect required.

A fallback nobody has run. A degradation path that was never tested fails when it is finally used, and that happens during an incident. Run each one on a schedule.

Degrading silently. If a degraded answer looks the same as a good one, you can end up serving it permanently by accident. Mark it, measure it, and alert on how often it happens.

Failing open on something that protects you. A rate limiter that lets everything through when its store is down is no longer limiting anything. Fall back to a local approximation instead, so the protection is weaker but still there.

Treating a health check as a correctness check. A process can be alive while its data is out of date. These need separate signals.

Degrading the thing that mattered. Some answers have no acceptable approximation. The list of what must never degrade is part of this pattern, not an exception to it.

Spot a mistake, or something unclear? . Or get in touch.

Article

Send feedback

Thank you for helping. We read every report and fix what is wrong.

How do you feel about oneby7?

Sign in to oneby7

Keep your progress, your streak and your code, on any device.

New here? This creates your account too.