Course contents

09. Reliability and Resilience Lesson 9 of 10

Graceful Degradation

Keep serving when a dependency fails: cache fallbacks, serving stale data, optional features and priority-based load shedding, simulated step by step.

15 minIntermediate7 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • A hard dependency’s outages become your outages; optional ones should never be hard.
  • Caches, stale data and defaults are fallback paths that do not need the failed dependency.
  • Serving stale data is a per-field decision with an honest label.
  • Under overload, shed the least valuable traffic early and cheaply instead of failing everyone.
  • Judge degradation per traffic class: overall error rate can rise while users are better off.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

Graceful degradation means a system keeps delivering its most important function, with reduced features, older data or less capacity, when parts of it fail or are overloaded, instead of failing completely. The opposite is a system where any failing piece produces an error page.

Why it exists

Every service has dependencies, and some of them will be down or slow at any given moment. If a page needs all ten of its dependencies, its availability is roughly the product of theirs, and an optional widget can take down checkout. Overload behaves the same way: without a decision about what to drop, the system drops a bit of everything, including the requests that matter most.

How it works

Classify dependencies. For each call ask: can the response be useful without it? A product page needs the product; it does not need recommendations, reviews or a personalised banner. Optional calls get short timeouts and circuit breakers, and the page renders without them.

Fallback paths. Things that can answer without the failed dependency:

  • Cache: entries already cached keep serving; with a cache in front, a database outage fails only the misses.
  • Stale data: keep entries past their TTL and serve them while the source fails (HTTP's Cache-Control: stale-if-error and stale-while-revalidate, RFC 5861). Label what may be outdated.
  • Safe defaults: a generic "popular items" list, a default configuration, a cached feature-flag snapshot.
  • Reduced functionality: read-only mode, search without facets, queueing an action for later ("we'll email your receipt").

Load shedding. When demand exceeds capacity, reject some work early and cheaply so the rest succeeds. Shed by priority: bots, prefetch, analytics and batch jobs first; paying users' critical journeys last. Static budgets per traffic class are simple; adaptive shedders reject based on queue time, concurrency or CPU (for example, rejecting when requests have waited longer than they could still succeed). Return 429 or 503 with Retry-After so well-behaved clients back off.

Brownouts and kill switches. Feature flags that turn expensive features off under load or during an incident, ideally automatically, so the decision does not wait for someone to find the right config.

When to use it

On every user-facing path with more than one dependency, and for any service that can be overloaded by traffic it does not control (public APIs, crawlers, retry storms after an outage).

When not to

  • When a wrong answer is worse than no answer: payments, permissions, medical or financial data that must be current. Fail closed, clearly.
  • When the fallback costs more than the failure it hides: a degraded mode that is never exercised adds code that may itself fail.
  • As a substitute for capacity planning: shedding is for spikes and incidents, not for permanent under-provisioning.

Trade-offs

Choice You gain You pay
Serve stale on error Most pages keep working Users may act on outdated data; needs labels and checks at commit points
Optional features with fallbacks Their outages stay invisible More code paths to test; product decisions per feature
Static per-class budgets Simple, predictable shedding Wasted capacity when the high-priority class is quiet
Adaptive shedding Uses capacity fully, reacts to real overload Harder to reason about and tune
Fail open (allow when the checker is down) Availability Risk of letting through what should have been blocked

Alternatives

  • More redundancy for the dependency itself (replicas, failover): fixes the cause instead of hiding it, but costs more and never reaches 100%.
  • Asynchronous processing: accept the request into a queue and finish later, so a slow dependency does not block the user.
  • Static fallback pages served from a CDN when the origin is completely down.

Failure modes

  • Optional dependency, hard in practice: no timeout or no fallback, so a slow recommendations service hangs the page.
  • Fallback never tested: the stale path has a bug, or the default config is years old.
  • Silent staleness: users see outdated prices or stock without any hint.
  • Shedding the wrong traffic: rejecting by arrival order instead of value; or shedding after expensive work has already been done.
  • Retry storms: shed clients retry immediately and multiply the load; send Retry-After and use backoff with jitter.

In production

List the degraded modes per user journey before an incident: what turns off, what goes stale (and for how long), what is shed first. Wire them to circuit breakers and feature flags, and test them with fault injection and game days. Monitor per traffic class: success rate and latency for checkout, browse and bots separately, plus how often fallbacks are used, because a fallback that serves 30% of traffic hides a real outage.

Common misconceptions

  • "Failing fast is graceful." It protects the servers; the user still gets an error unless there is a fallback.
  • "A higher error rate after adding shedding means it made things worse." Shed errors are deliberate; look at the important traffic.
  • "Stale data is always wrong." Much data (descriptions, images, catalogue structure) is fine an hour old; decide per field.
  • "Degradation is only an engineering decision." What may be turned off or shown stale is a product decision; make it ahead of time.

Interview angle

When drawing a page that calls several services, say which dependencies are critical and which degrade, and how: timeouts, circuit breakers, cached or stale fallbacks, defaults. For overload, describe priority-based shedding at the edge and why it beats letting every request time out. Interviewers like hearing that you would measure success per journey and test the degraded modes regularly.

Model assumptions

The engine runs all traffic and failures. Arrivals are Poisson: shoppers 150 req/s, bots and prefetch 60 req/s (400 during the surge). The Product API has 20 workers, a 30 ms mean service time (lognormal, cv 0.35) and room for 64 waiting requests. The database has 10 connections and 20 ms mean reads. The cache answers a fixed share of requests (70% hits) in about 1 ms; on a miss with the database down the request fails at once (connection refused). Serving stale on error is modelled as the hit ratio rising to 97% while the database is down. The low-priority lane stands for a gateway that classifies requests; its shedding is a token bucket of 60 req/s (burst 20). Numbers are illustrative, not benchmarks. Latency percentiles (P50, P95, P99) are computed over the requests that succeeded in the last 5 simulated seconds: failed, rejected and timed-out requests are not in them and are counted in the Errors tile, which is always shown next to them. Rejecting or timing out the slowest requests therefore improves the percentiles while making the system less reliable, so read the two together.

The lesson as textEvery step of the simulation, written out.
  1. 1. Every page needs the database

    Shoppers load product pages at 150 requests per second; bots and prefetching add another 60 through a separate low-priority lane. The Product API reads every product from the database before it answers.

    The API is a bit over half busy and every request succeeds. But the database is a hard dependency: the API has no answer without it.

    Scene: Shoppers and bots call the Product API, which reads every product from the database. The API is a bit over half busy; every request succeeds.

    Key idea: A hard dependency’s availability caps yours: if the page cannot render without it, its outages are your outages.

  2. 2. The database goes down, and so does everything

    At 1 s the database fails. Every request needs it, so every request fails: shoppers get an error page instead of a product page, even for the most popular products that were read a thousand times a minute ago.

    The API itself is fine and fails fast (the connection is refused at once). But failing fast is not the same as failing well: the user still sees an error.

    Scene: The database fails at 1 second. From then on every request fails, for shoppers and bots alike.

    Key idea: Failing fast protects your servers. Failing gracefully protects your users: give them something useful instead of an error.

  3. 3. A cache answers what it already knows

    The database is back, and the API now reads through a cache first. About 70% of reads are answered from it; misses go to the database and fill the cache.

    At 1 s the database fails again. Cache hits still succeed, so about 70% of pages still render. Only misses fail. The cache was added for speed, but it is also a fallback path: a partial answer source that does not need the failed dependency.

    Scene: A cache now sits in front of the database. When the database fails at 1 second, cache hits keep succeeding and only misses fail: roughly 30% of requests.

    Key idea: Anything that can answer without the failed dependency (cache, replica, static default) turns a total outage into a partial one.

  4. 4. Stale is better than nothing

    Normally entries expire after their TTL, which is why 30% of reads miss. Many of those misses are for products the cache did have, just past their TTL. With stale-if-error the API keeps expired entries around and serves them when the database is failing, marked as possibly outdated (“prices as of 14:02”).

    The database fails at 1 s and the API switches to serving stale entries: only products that were never cached fail, about 3%. (The model shows this as the hit ratio rising to 97% while the database is down.) HTTP has the same idea built in: Cache-Control: stale-if-error and stale-while-revalidate.

    Scene: The database fails at 1 second and the API starts serving expired cache entries. Only about 3% of requests, for products never cached, fail.

    Key idea: Decide per field how stale is acceptable. A product description from an hour ago is fine; a stock count may need a “check at checkout” warning.

  5. 5. A bot surge drowns the shoppers

    The database is healthy again and the cache back to normal. At 1 s a crawler hammers the site: low-priority traffic jumps from 60 to 400 requests per second.

    The API can handle roughly 460 per second in total; now it gets 550. Its workers stay busy, its queue fills, and it starts rejecting requests with 503, without caring who sent them. Shoppers, the traffic that pays, lose pages to bots, and their latency climbs.

    Scene: Bot traffic jumps to 400 requests per second. The Product API is overloaded: its queue fills, latency rises and it rejects requests from shoppers and bots alike.

    Key idea: Overload does not respect priorities. Without a decision about what to drop, you drop a bit of everything.

  6. 6. Shed the traffic that matters least

    Load shedding: when there is not enough capacity for everything, drop the least important work on purpose, early and cheaply. The low-priority lane gets a budget of 60 requests per second; anything above is answered immediately with 429 Too Many Requests and never reaches the API.

    The API is back to about 210 requests per second, about half busy. Shoppers see no errors and normal latency again. The overall error rate looks worse than before, but every error is a bot request that can retry later. Errors are not all equal: measure them per traffic class.

    Scene: The low-priority lane now admits 60 requests per second and rejects the rest at once. The Product API is about half busy and shoppers see no errors.

    Key idea: Shed by priority at the edge: rejecting low-value work cheaply keeps capacity for high-value work.

  7. 7. Plan the degraded modes before you need them

    The surge is over and everything is healthy.

    Graceful degradation is a list of decisions made in advance: which features are optional (recommendations, reviews, personalisation) and can be hidden when their service fails; which data can be served stale and for how long; which defaults are safe (a generic “popular items” list); which traffic can be shed first; and how the UI tells users what is reduced. Wire each into the code with timeouts and circuit breakers, put switches behind feature flags, and test them with fault injection: a fallback that has never run usually fails when you need it.

    Scene: Shoppers at 150 and bots at 60 requests per second; the low-priority lane keeps its 60 per second budget. Everything is healthy and every request succeeds.

    Key idea: Degrade by design: know what to turn off, what to serve stale and what to shed, and rehearse it.