Skip to content

    Frontend System Design

    Graceful Degradation

    Design a page that keeps working when parts fail: rank parts by importance, step down from live to saved to default to nothing, detect features not browsers.

    By Published 13 min read

    • frontend-system-design
    • graceful-degradation
    • resilience
    • feature-detection
    • fallbacks
    Share

    Standard lessonintermediateReact labFrontend System Design

    Before this: Error Boundaries and Global Error Handling

    What you'll learn: By the end of this lesson you will be able to rank the parts of a page by importance, give each part a ladder of fallbacks (live data, a saved copy, a built-in default, nothing), put a timeout on every source, decide when a page is full, degraded or blocked, tell the user honestly what they are seeing, and use feature detection so a missing browser capability reduces the experience instead of breaking it.

    Think of a car that enters "limp-home" mode when a sensor fails: it still gets you to a garage, slower and with a warning light, instead of stopping on the motorway. A well-designed page does the same. The shopper wants to buy oat milk; the reviews service being down should cost them the reviews, not the purchase.

    The running example is the product page of a grocery marketplace (the front end of the ShopStream course project): a price block, a stock line, a reviews list and a "you may also like" strip, each filled by a different service.

    The core idea

    1. Not all parts are equal. A page has a job (here, buying). Parts that the job cannot do without are critical; parts that help are important or optional.
    2. Each part steps down, one rung at a time. Live data, then a saved copy if it is young enough, then a built-in default, then nothing. The rung it lands on depends on the part's importance.
    3. The page decides what the sum means. All live is full; anything not live is degraded; a missing critical part is blocked, and the page must say so plainly.

    Graceful degradation, as MDN defines it, is a design philosophy about building something that works in the newest browsers but falls back to an experience that, while not as good, still delivers essential content and functionality in older ones. The same idea applies when it is a service, not a browser, that is missing.

    Degradation and enhancement

    MDN describes progressive enhancement as providing a baseline of essential content and functionality to as many users as possible, while delivering the best experience only to users of the most modern browsers. It adds that the two approaches are related, are often seen as going in opposite directions, and are in reality both valid and often complementary. In practice a team does both: build the baseline first, enhance when a capability is present (enhancement), and decide what happens when a dependency is missing at runtime (degradation).

    The tool that links the two is feature detection. MDN describes it as working out whether a browser supports a block of code and running different code depending on the answer, so the browser can always provide a working experience instead of crashing. It warns against confusing this with browser sniffing, which it calls a practice to be discouraged. Its examples include testing for a property with the in operator ("geolocation" in navigator), CSS.supports() in JavaScript, and the @supports at-rule in CSS, which MDN calls the preferred method for CSS features.

    The ladder

    Figure 1. A part's ladder

    flowchart TD accTitle: The fallback ladder for one part of a page accDescr: A decision flow. Try the live source with a timeout. If it answers, show live data. If it fails or times out, check for a saved copy that is young enough, and show it with a note giving its age. Otherwise check for a built-in default and show it with a note that it is general information. Otherwise omit the part, saying nothing for an optional part, a status line for an important one and an alert for a critical one. A["Ask the live source
    with a timeout"] -->|"answers in time"| L["Show live data"] A -->|"error or timeout"| B{"Saved copy,
    young enough?"} B -->|"yes"| S["Show it, say how old"] B -->|"no"| C{"Built-in default?"} C -->|"yes"| F["Show it, say it is general"] C -->|"no"| O["Omit: optional says nothing,
    important says unavailable,
    critical raises an alert"]

    How to read this: each "no" moves down one rung. The rungs a part has are a design decision per part: a price has no saved-copy rung at all, because showing a stale price at checkout is worse than showing none.

    Three questions define a part's ladder.

    • How long do I wait? Every source needs a timeout, or "slow" becomes "down" for the user without any rung ever being reached. AbortSignal.timeout(), per MDN, returns a signal that aborts after a time; it aborts with a TimeoutError, and the timeout is based on active time, so it pauses while the document is in the back-forward cache.
    • How old may a saved copy be? The server-side analogue is the stale-if-error cache extension from RFC 5861: when an error is encountered, a cached stale response may be used, and the extension's value limits how stale. Defining your own limit per part, as the lab does with maxStaleMs, is the same idea. maxStaleMs of zero means never, which is the right answer for a price.
    • What is the default? Generic text ("Check stock at the shop") is better than a blank where the user expected information, but it must not pretend to be data.

    Illustration 1: the minimal example

    The core of the lab is one function that walks the ladder, abridged here:

    async function loadWithDegradation<T>(plan: LoadPlan<T>, scheduler: Scheduler): Promise<Outcome<T>> {
      let reason: string;
      try {
        return { mode: "live", value: await withTimeout(plan.fetchLive(), plan.timeoutMs, scheduler) };
      } catch (error) {
        reason = error instanceof Error ? error.message : String(error);
      }
      const cached = plan.readCache?.();
      if (cached !== undefined) {
        const ageMs = scheduler.now() - cached.storedAt;
        if (ageMs <= plan.maxStaleMs) return { mode: "stale", value: cached.value, ageMs, reason };
      }
      if (plan.fallback !== undefined) return { mode: "fallback", value: plan.fallback, reason };
      return { mode: "omitted", reason };
    }

    The scheduler is injected, so a test can say "800 ms have passed" without waiting. The return value names the rung, so the view cannot show a saved copy as if it were live.

    Telling the user the truth

    A degraded part must say what it is. A stale part shows a note with its age ("Saved copy from 5 minutes ago"); a default shows a note that it is general information; an omitted optional part may say nothing, but an omitted important part says it is unavailable, and an omitted critical part is an alert. The lab marks the notes with role="note", the unavailable lines with role="status" and the critical failure with role="alert", and its tests check those roles and texts only in jsdom: no screen reader was used here.

    A page-level line ("Some parts of this page are showing saved or reduced content: reviews") lets a user, and a support agent reading a screenshot, see that the page is not complete.

    One trap: do not decide "online or offline" from a flag. MDN says navigator.onLine is inherently unreliable (a LAN connection counts as online even when it has no internet access) and that you should not disable features based on it, only provide hints when the user may seem offline. Degrade on what actually failed, the request, not on a guess about the network. The lesson on offline UX patterns covers the offline side in depth.

    Figure 2. A slow source, a timeout, a saved copy

    sequenceDiagram accTitle: A reviews call times out and a saved copy is shown accDescr: The page asks the reviews service for data and starts an 800 millisecond timer. The service does not answer. The timer fires, the page gives up on the live call and reads its saved copy, which is five minutes old and within the allowed age. It shows the copy with a note. If the service answers later, nothing changes on screen. participant P as Reviews part participant S as Reviews service participant C as Saved copy P->>S: fetch reviews Note over P: start 800 ms timer Note over S: no answer Note over P: timer fires, give up P->>C: read C-->>P: copy, 5 minutes old Note over P: show copy and the note "Saved copy from 5 minutes ago" S-->>P: late answer (ignored)

    How to read this: the page gives up on its own schedule, not the service's. The late answer at the end changes nothing on screen, and the lab has a test that it does not throw.

    From parts to a page

    The page rule has three outcomes, and the difference between degraded and blocked is the whole design.

    Page level When What the user sees
    Full Every part is live The normal page
    Degraded Some part is saved, default or omitted, but no critical part is omitted The page, with notes and a banner
    Blocked A critical part is omitted A clear message that the page cannot continue

    A part can also be live and still break: the data arrived, and drawing it threw. That is the case the previous lesson, on error boundaries and global error handling, covers: wrap each part's rendering in a boundary so an optional part that cannot be drawn shows nothing, and the page stays. Graceful degradation handles the failing source; the boundary handles the failing drawing; a good page needs both.

    Figure 3. Importance decides the outcome

    Product page parts by importance and what each shows when its source is downPrice to Page rule (omitted: blocked); Stock to Page rule; Reviews to Page rule; Recs strip to Page rule; Page rule to ShopperPrice: critical, never stalePricecritical, neverstaleStock: important, default textStockimportant,default textReviews: optional, saved copyReviewsoptional, savedcopyRecs strip: optional, nothingRecs stripoptional, nothingPage rule: full, degraded, blockedPage rulefull, degraded,blockedShopper: notes and bannerShoppernotes and banneromitted: blocked

    How to read this: the red arrows are each part's failure path. Only the price (the first, accent box) can make the page blocked; the others lower it to degraded. The importance and rungs shown are the example's decisions, not a standard.

    Illustration 2: the realistic example

    The lab runs the four-part product page under six failure scenarios with virtual time and prints each part's mode and the page level; the trace is in the next section. Two things to look for there: a hanging source and a failing one land on the same rung, and one failed part can lower the page to degraded while another blocks it.

    Build it

    The lab is examples/frontend/labs/graceful-degradation-model (Node 26.13.1, React 19.3.1, Vitest 5.1.0), with a pure core (src/core.ts) and a thin React product page that reuses the boundary of the error-boundary lab.

    cd examples/frontend/labs/graceful-degradation-model
    pnpm test        # 22 tests (15 pure, 7 in jsdom)
    node src/demo.ts

    Expected output, captured from a real run (Node 26.13.1, node src/demo.ts, virtual time):

    virtual time: the clock starts at minute 5; a saved copy of reviews exists, stored at minute 0
    per-part rules: price never from a saved copy; stock has a built-in fallback; reviews may be 10 minutes stale
    
    everything up
       price=live stock=live reviews=live recs=live
       page: full
    reviews service returns 503 (saved copy exists)
       price=live stock=live reviews=stale recs=live
       page: degraded (not live: reviews)
    reviews service hangs (saved copy exists)
       price=live stock=live reviews=stale recs=live
       page: degraded (not live: reviews)
    stock service returns 503
       price=live stock=fallback reviews=live recs=live
       page: degraded (not live: stock)
    recommendations hang and price returns 503
       price=omitted stock=live reviews=live recs=omitted
       page: blocked (not live: price, recs)
    everything hangs
       price=omitted stock=fallback reviews=stale recs=omitted
       page: blocked (not live: price, stock, reviews, recs)
    
    feature detection
       no IntersectionObserver      -> load-more-button
       with IntersectionObserver    -> load-on-scroll

    Reading it: a failing and a hanging reviews service land on the same rung, because the timeout turns "hangs" into "failed". When the stock service is down, the page is only degraded: a default is shown. When the price fails, the page is blocked even though three parts are fine. In the last scenario everything hangs and the page is blocked, but reviews and stock still show something. The last two lines are the baseline-first rule: the button works everywhere, the scroll observer is added when the capability is present.

    What the lab does not show. Time is virtual, so no real timer, network or browser was involved. Its timeout stops waiting but does not abort the request: a real client would also pass an abort signal. The notes and roles were tested in jsdom only, and nothing about how they look or sound was observed.

    Break it. In pageHealth in src/core.ts, remove the line that sets blocked for a critical part. The test "blocked only when a critical part is omitted" fails. Restore it.

    Illustration 3: the failure case

    Two things the tests caught. First, an optional recommendation with a missing name arrived successfully, so its mode was live, but drawing it threw; only the boundary kept the rest of the page. A mode that says "live" does not say "drawn". Second, a price that hangs must never be replaced by a saved price: the lab's maxStaleMs of zero for the price makes it omitted, and the page blocked, which is the honest result.

    Trade-offs

    Choice Gain Cost
    Saved copy for a slow part The user still sees something useful The data can be stale, so it must be labelled
    Built-in default text No blank area It can read like real data if worded badly
    Omit an optional part silently A calm page The team may not notice a broken part without reports
    Short timeouts A fast fall back More false failures on slow networks
    Block when a critical part fails Never a wrong price Fewer sessions complete
    Feature detection Works across environments A code path per capability to test

    In practice: the reviews outage

    NOTE

    This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.

    The situation

    The product page fetches price, stock, reviews and recommendations together and waits for all of them before drawing anything. The reviews service has an incident and answers after 30 seconds, or not at all. Shoppers see a spinner for half a minute, and then leave.

    Starting architecture

    Figure 4. One wait for everything

    Starting architecture: the page waits for all four sourcesProduct page to Price API; Product page to Reviews API (30 s); Product page to Recs APIProduct page: waits for allProduct pagewaits for allPrice APIPrice APIReviews API: down or slowReviews APIdown or slowRecs APIRecs API30 s

    How to read this: the amber page waits on all three services, so the slowest one sets the wait for the page. The red edge is the 30-second call.

    Options considered

    Option What it fixes What it costs Risk
    Make the reviews service faster The cause Work in another team Does nothing during the next incident
    Load every part independently, with timeouts The page no longer waits on the slowest A loading state per part Layout shifts as parts arrive
    Independent parts with a ladder and a page rule The page degrades honestly A ladder and tests per part Saved copies shown too long

    The decision

    Field Decision record
    Context One optional dependency makes the whole page unusable during an incident.
    Decision Load each part on its own with an 800 ms timeout (an illustrative figure). Rank the parts: price critical and never from a saved copy, stock important with default text, reviews and recommendations optional. Reviews may show a saved copy up to ten minutes old with a label. Add a page banner when any part is not live.
    Consequences, good The page is usable during a reviews outage; the failure is visible, not silent.
    Consequences, bad More states to design, and the banner can alarm people for a harmless optional part.
    Revisit when Reports show a part on its fallback much of the time, or a part's importance changes.

    Rollout and verification

    1. Write the importance table first and have product agree what is critical.
    2. Test each rung of each ladder with fake time and fake sources.
    3. Force each failure by hand in a staging environment: a 503, a hang, an empty body, a slow response.
    4. Reserve space for parts that may arrive late so the layout does not jump.

    The 2 a.m. failure

    The saved copy of the reviews has no age limit in the first release. During a long outage, shoppers see reviews that are two days old, including one for a product that has since been recalled, with no sign that it is old.

    First three checks: (1) does every saved copy have a maximum age; (2) is the age shown to the user; (3) can a part be switched to "omit" without a release. Mitigation: set the maximum age to zero for the affected part, so it is omitted. Follow-up: a test that fails when a part has a saved-copy rung with no maximum age.

    Architect's notes

    • Start from the job of the page. Decide the critical parts before talking about fallbacks.
    • Every saved copy needs an age limit and a label. Stale data without a label is a wrong answer.
    • Never degrade a value people act on silently. Prices, balances and availability at checkout are blocked, not guessed.
    • Timeouts are part of the design. A rung is reached only when something gives up.
    • Report what degraded. A part that is on its fallback for days is a defect, not a feature.
    • Back-end side. On the server the same idea appears as circuit breakers, load shedding and cached responses; the client's ladder is how those decisions look on the screen.

    Common mistakes

    • Waiting for every source before drawing anything.
    • No timeout, so "slow" never becomes a fallback.
    • A saved copy with no age limit, or no label.
    • Showing a stale price or balance.
    • Choosing by browser name instead of by capability.
    • Treating navigator.onLine as a fact.
    • A "live" part that was never drawn, because no boundary stopped its render error.

    Key takeaways

    • Rank parts by importance; only critical parts can block the page.
    • Each part has a ladder: live, saved copy within an age limit, built-in default, nothing.
    • Put a timeout on every source and inject the clock so tests can use virtual time.
    • Say what the user is looking at: saved, general or unavailable.
    • Detect features, do not sniff browsers, and keep a baseline that works without them.
    • A boundary protects the drawing; degradation protects the data. Use both.

    Practice exercises

    Exercise 1: Starter (30 min). For a page you know, list its parts and mark each critical, important or optional, with the rung each would land on when its source is down.

    Exercise 2: Intermediate (2 hours). In the lab, add a fifth part, "delivery estimate", important, with a saved copy of 15 minutes, and extend the demo with a scenario for it.

    Exercise 3: Advanced (half day). Make the timeout abort the request with a signal, and add a test that a late answer is discarded and not cached as fresh.

    In this course:

    The previous lesson in this module covers error boundaries and global error handling; the next covers resilient UI and client circuit breakers, and the lessons on offline UX patterns and the failure modes of front-end systems follow. They are named here in plain text because they are not published yet.

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments