Graceful Degradation
AdvancedGraceful degradation allows a system to continue operating with reduced functionality when a component fails, rather than failing completely. Users get a degraded experience instead of an error page.
Overview
Graceful degradation is a design philosophy where the system provides the best possible experience even when some components are unavailable. Instead of showing a 500 error when the recommendation service is down, an e-commerce site shows popular products instead. Instead of failing a checkout when the loyalty points service is unreachable, it processes the order without applying points and applies them later. Techniques include fallback responses (cached data, static defaults), feature flags (disable non-critical features), load shedding (reject low-priority requests to protect high-priority ones), and timeout budgets (allocate a time budget across dependent calls). Graceful degradation requires identifying which features are critical (must always work) and which are non-critical (can be temporarily disabled).
Fallback Strategies
When a dependency fails, return cached data, default values, or a simplified response instead of an error. Classify dependencies as critical (block on failure) or non-critical (fallback on failure).
// E-commerce product page — graceful degradation
public ProductPageResponse getProductPage(String productId) {
// Critical — must succeed or fail the request
Product product = productService.getProduct(productId);
// Non-critical — fallback on failure
List<Product> recommendations;
try {
recommendations = recommendationService.getFor(productId);
} catch (Exception e) {
recommendations = popularProductsCache.getTopSelling(); // fallback
log.warn("Recommendation service unavailable, using popular products");
}
// Non-critical — return empty on failure
List<Review> reviews;
try {
reviews = reviewService.getReviews(productId);
} catch (Exception e) {
reviews = List.of(); // empty list as fallback
}
return new ProductPageResponse(product, recommendations, reviews);
}Load Shedding & Priority Queues
When the system is overloaded, shed low-priority traffic to protect high-priority operations. Payment processing should succeed even if recommendation calls are dropped.
// Load shedding — protect critical operations
// Priority levels:
// P0: Payment processing, order creation (NEVER shed)
// P1: Search, product listing (shed under extreme load)
// P2: Recommendations, analytics (shed first)
// P3: Background jobs, reports (pause during incidents)
// Envoy proxy — priority-based rate limiting
routes:
- match: { prefix: "/api/v1/payments" }
priority: HIGH # never shed
- match: { prefix: "/api/v1/search" }
priority: DEFAULT # shed under extreme load
- match: { prefix: "/api/v1/recommendations" }
priority: LOW # shed first
// Feature flags for graceful degradation
@GetMapping("/api/v1/homepage")
public HomePageResponse getHomepage() {
HomePageResponse response = new HomePageResponse();
response.setProducts(productService.getFeatured());
if (featureFlags.isEnabled("show-recommendations")) {
response.setRecommendations(recoService.getPersonalised());
}
if (featureFlags.isEnabled("show-trending")) {
response.setTrending(trendingService.get());
}
return response; // always returns something, even if bare-bones
}Key Points to Remember
- 1Graceful degradation provides reduced functionality instead of complete failure.
- 2Classify dependencies as critical (must work) and non-critical (fallback acceptable).
- 3Fallback strategies: cached data, popular/default content, empty responses, static pages.
- 4Load shedding drops low-priority requests to protect high-priority operations under overload.
- 5Feature flags enable rapid toggling of non-critical features during incidents.
Interview Questions
Sign in to ask AriaWhat is graceful degradation and how does it differ from fault tolerance?
Give an example of graceful degradation in an e-commerce system.
What is load shedding and when would you use it?
How do feature flags help during production incidents?
Design a degradation strategy for a ride-hailing app when the map service is down.
Ask Aria about Graceful Degradation
Your personal AI tutor — ask anything about this concept
Revision Status
Personal Notes
Sign in to save personal notes for this topic.
Discussion
Sign in to join the discussion.