Skip to content

Graceful degradation: what to switch off first

Deep diveConcept

One slow service, one box on the page, and every user gets an error. Here is how to decide in advance what can go missing, and how to serve a smaller page, shed load and keep the core working instead.

01 One slow box takes down the page

A shop's product page shows the product, its price, reviews and a "you may also like" box. On the busiest day of the year the recommendations service slows down. The page waits for it, the page server's threads fill up with waiting requests, and soon every product page returns 500. Nobody can buy anything, because of a box most shoppers ignore.

Graceful degradation means deciding in advance what the page can do without, and serving a smaller page instead of an error when part of the system is slow, broken or overloaded.

02 Why every extra dependency costs uptime

If a page needs every one of its dependencies to answer, its chance of working is the product of theirs. Five services that are each up 99.9% of the time give a page that works about 99.5% of the time, five times the downtime of any one of them.

Every call requiredAbout 99.5%Five services at 99.9%: 0.999^5 ≈ 0.995. Any one failing fails the page.
Only the product requiredAbout 99.9%The four optional calls can fail without failing the page, so the page is as available as its one hard dependency.

So the first step is a list: for each thing on the page, is it required or optional? Usually far fewer things are required than the code assumes.

03 Time budgets and fallbacks for optional calls

An optional call needs two things: a short time limit, and an answer to use when the limit passes. The limit matters as much as the fallback. A call that fails fast is easy to degrade; a call that hangs holds a thread, a connection and the user's patience.

A time budget and a fallback for an optional call
Step 1 of 6
One product page request (example timings)
BrowserPage serverProduct svcRecs svcNothing sent yet
  • just sent
  • timed out
  • page served

A shopper opens a product page. The page needs the product and its price, which it cannot do without, and recommendations, which are nice to have. The recommendations service is overloaded today.

0 ms elapsed
page.mjs
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
// Stand-ins for real services: prices are quick, recommendations are struggling.
const getProduct = async () => { await sleep(20); return { name: 'Kettle', price: 25 }; };
const getRecs = async () => { await sleep(900); return ['Mug', 'Teapot']; };
// Give an optional call a time budget; on timeout or error, use the fallback.
async function optional(promise, ms, fallback) {
let timer;
const timeout = new Promise((resolve) => {
timer = setTimeout(() => resolve(fallback), ms);
});
try {
return await Promise.race([promise, timeout]);
} catch {
return fallback;
Text
$ node page.mjs
Kettle 25 (no recommendations) under 200 ms

That is a real run on Node 24. The page is ready in under 200 ms even though recommendations take 900. The losing promise keeps running in the background; in a real service, pass an AbortSignal to the HTTP call so the work is cancelled too.

04 Decide what to switch off first

Under pressure, nobody should be deciding what matters. Write it down before the incident: what each feature is worth, what it costs, and what replaces it.

A news feed, ranked from last to switch off to first
FeatureIf it is missingFallback
Posts from people you followThe app is brokenNone: keep it up at all costs
Posting and commentsUsers cannot take partQueue writes and show them as pending
Ranked orderFeed feels less relevantNewest first
Like and view countsNumbers look staleCached or approximate counts
People you may knowNobody notices on the dayHide the box
Autoplay videoVideos need a tapShow a still image

Notice the middle column. The goal is not "on or off" but cheaper: an older copy, a simpler algorithm, an approximate number, a static image. A cached page from a minute ago is often better than a fresh one that never arrives.

05 Switching off under load

Failures are not the only trigger. When load passes what the system can serve, turning off expensive optional work frees capacity for the core. The switches are usually feature flags or kill switches that an operator, or an automatic rule on load, can flip without a deploy.

Switching features off as load rises
Step 1 of 6
Feed page features
Posts
Like counts
Comments
Ranking
Suggestions
Autoplay
Degradations, in order
Empty
  • switched off
  • cheaper version
  • just taken
  • request shed

A news feed at a normal hour. Every feature is on. The team has already ranked them: the posts are the product, everything else can go.

60% of capacity load

A fallback that has never run is probably broken. Flip your kill switches regularly in production, during quiet hours or in planned game days, and check the page still renders. Teams that only find out on the bad day often learn the fallback calls the same overloaded service.

06 Shedding load: a fast no beats a slow yes

When even the core cannot keep up, the server must refuse some requests. Refusing early is cheap: a 503 costs almost nothing to send. Accepting everything means every request gets slow, many time out on the client, and the server spends its time on work nobody is waiting for any more.

Accept every requestEveryone times outQueues grow, latency passes the client timeout, and the server does full work for answers that are thrown away.
Shed the excess earlyMost get a fast pageRequests over capacity get an immediate 503 with Retry-After. The rest are served at normal speed.
  • Shed by priority. Background refreshes, prefetching and analytics go before a user tapping "buy". Mark priority on the request, for example in a header set at the edge.
  • Limit concurrency, not just rate. Cap the requests in flight per server; when the cap is reached, reject instead of queueing.
  • Drop requests that waited too long. If a request has been queued longer than the client's timeout, the client has already given up. Skip it.
  • Shed at the edge. The earlier a request is refused, the less work was spent on it.

07 How degradation goes wrong

A fallback heavier than the originalIf the cache is down and the fallback is "read from the database", every request now hits the database at once. A fallback must be cheaper than what it replaces, or it moves the outage instead of avoiding it.
A hidden hard dependencyThe page treats recommendations as optional, but every request also checks a session service, a config service or a feature-flag service. If that one is down, nothing renders. Find these by switching each dependency off in a test environment.
timeout: 30000Library default timeoutsMany HTTP clients wait 30 seconds or more, or have no overall request timeout at all, unless you set one. An optional call with a default timeout is not optional; it just fails slowly.
Retrying a struggling serviceFalling back after three retries triples the load on the service that is already slow. For optional calls, try once with a short budget, and use a circuit breaker to stop calling a service that keeps failing.
Degraded and nobody knowsIf the fallback hides the failure completely, the team may not notice for days. Count fallbacks served and alert on them, and tell users when it matters, for example "Like counts may be delayed".

08 Check yourself

Question

A checkout page calls payments, stock, a fraud check and a "frequently bought together" service. Which is the best candidate for a fallback that simply hides it?

Question

Your recommendations call has a 150 ms budget and a fallback, but the HTTP client's timeout is still the 30 s default and the call is not cancelled. What can still go wrong?

Question

Under overload, why is a fast 503 for some users better than serving everyone slowly?

09 Practise this

Was this tutorial useful?Your vote tells us what to improve next.
Spotted a mistake, or something unclear?