Frontend System Design · Lesson 55 of 86 · 4 min
Graceful Degradation and Fallback UIs
This is how you demonstrate you build for reality, not just the happy path.
After this, you'll be able to articulate a clear strategy for application resilience. You won't just say "we should handle errors"; you'll specify how and where to build fault tolerance into the UI, from the component level to the entire application.
Distinguish Graceful Degradation from Fallback UIs
These terms are often used interchangeably, but they aren't the same. Using them correctly in an interview signals precision.
Graceful degradation is a top-down, proactive strategy. You build the full-featured experience assuming a modern environment (latest browser, fast network), then systematically remove or simplify features for less capable environments. The core functionality remains, but the bells and whistles are stripped away.
Fallback UIs are a reactive strategy. They are specific, alternative UIs displayed when a part of your application fails at runtime. This isn't about browser capability; it's about handling transient states like network errors, API failures, or component crashes.
The interview question: "How do these concepts relate to Progressive Enhancement?"
Your answer: "Progressive Enhancement is the inverse of Graceful Degradation. You start with a baseline of core content and functionality that works everywhere, then add layers of enhancement for more capable browsers. Graceful Degradation starts with the enhancements and subtracts them. Fallback UIs are a tool used within either strategy to handle runtime errors."
Implement Component-Level Fault Tolerance
A single, non-critical component should never crash your entire application. The primary tool for preventing this in React is the Error Boundary. It's a class component that catches JavaScript errors in its child component tree and renders a fallback UI.
The trap: Candidates often forget this pattern exists and suggest try...catch inside functional components, which only works for imperative code (like event handlers), not for errors during rendering.
An Error Boundary is your answer to "How do you design a dashboard where a failing third-party widget doesn't take down the whole page?" You wrap each independent widget in its own ErrorBoundary.
Here is a minimal, reusable ErrorBoundary.
import React, { Component, ErrorInfo, ReactNode } from 'react';
interface Props {
children: ReactNode;
fallbackUI: ReactNode;
}
interface State {
hasError: boolean;
}
class ErrorBoundary extends Component<Props, State> {
public state: State = {
hasError: false,
};
public static getDerivedStateFromError(_: Error): State {
return { hasError: true };
}
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
// You would log this to a service like Sentry here.
console.error("ErrorBoundary caught an error:", error, errorInfo);
}
public render() {
if (this.state.hasError) {
return this.props.fallbackUI;
}
return this.props.children;
}
}
export default ErrorBoundary;
This component is a container. If anything inside it throws an error during render, the boundary catches it, logs it, and displays your predefined fallbackUI instead of a white screen.
Handle Data States Beyond a Simple Spinner
When a component fetches data, it exists in more states than just "loading" and "done". A robust design accounts for all of them. Your goal is to manage user perception and prevent layout shifts.
-
Loading State: A spinner is the minimum. A skeleton UI is better. It mimics the shape of the eventual content, reducing perceived load time and preventing the page from jumping around when the real content appears. This is crucial for Core Web Vitals, specifically Cumulative Layout Shift (CLS).
-
Error State: Don't just show "Error". Show an inline message explaining what failed (e.g., "Could not load recommendations") and provide a retry button. A full-page reload is a blunt instrument; a targeted refetch for the failed component is a much better user experience.
-
Empty State: The API call succeeded, but returned no data. This is not an error. Instead of a blank space, render a clear message ("No products found matching your filter") and, if appropriate, a call to action ("Clear filters").
The trap: Only mentioning a loading spinner. Senior candidates discuss the UX and performance trade-offs between spinners, skeletons, and the importance of stable empty states.
Degrade Features Based on Environment
You can't assume every user has access to every browser API. Graceful degradation requires you to check for features before you use them. This is called feature detection.
For example, instead of just using the IntersectionObserver API for infinite scroll, you build a system that degrades gracefully if it's not available.
This flow ensures the core function—loading more content—is always available, even if the implementation is less efficient on older browsers.
The interview question: "How would you design a component that uses the Web Share API?"
Your answer: "First, I'd check if
navigator.shareis available. If it is, I'd render a button that calls it. If not, I'd gracefully degrade. The fallback could be a button that copies the URL to the clipboard, or it could show a set of traditionalmailto:and social media links. The component's public API wouldn't change, but its rendered output would adapt to the environment."
This demonstrates an understanding of building for a heterogeneous web, not just a single browser. It's about resilience and reach.
Try it
Take a simple component that fetches and displays data. Implement fallbacks for its loading, error, and empty states. For the loading state, build a simple CSS-only skeleton UI that approximates the final content's layout.
Next: You'll learn how to measure the real-world impact of these failures with Real User Monitoring (RUM).
Lock it in — apply this lesson under interview conditions.