Graceful Degradation
When a dependency is down, serve a cached or partial result with a banner rather than failing the whole page, and keep the write path honest.
On this page
Introduction
This guide covers graceful degradation under dependency failure, a recurring concern in the resilience scenario. A page that 500s because one secondary widget failed is worse than the same page without the widget. Serving a cached or partial result with a small banner, while keeping the write path honest so you do not silently drop user data, is the difference between a blip and an outage for the user.
Critical vs nice-to-have
Sort dependencies into critical and nice-to-have, so a failure in the latter degrades instead of failing the whole page.
The trade-off worth naming is that sort dependencies into critical and nice-to-have, so a failure in the latter degrades instead of failing the whole page adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
Serve cached or partial
When a nice-to-have fails, serve a stale cached value or a partial result so the page still renders, which is the graceful part.
The trade-off worth naming is that when a nice-to-have fails, serve a stale cached value or a partial result so the page still renders, which is the graceful part adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
let recs;
try { recs = await fetchRecommendations(); }
catch { recs = cache.get('recs') ?? []; partial = true; }
render({ recs, partial });
Show a banner
Tell the user something is degraded with a small banner, so they know the data may be stale rather than assuming it is current, which is the honest part.
The trade-off worth naming is that tell the user something is degraded with a small banner, so they know the data may be stale rather than assuming it is current, which is the honest part adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
Honest writes
Never degrade a write by silently succeeding; queue it and tell the user it is pending, or fail it, so you do not lose data to graceful degradation.
The trade-off worth naming is that never degrade a write by silently succeeding; queue it and tell the user it is pending, or fail it, so you do not lose data to graceful degradation adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
try { await save(data); }
catch { await queue.add(data); res.status(202).json({ pending: true }); }
Measure the degradation
Track how often the fallback is used so a dependency that is always degraded is noticed and fixed, rather than silently shipping a partial page.
The trade-off worth naming is that track how often the fallback is used so a dependency that is always degraded is noticed and fixed, rather than silently shipping a partial page adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
Test the fallback
Make a nice-to-have fail, assert the page renders with a banner, and assert a write still fails honestly, so degradation is correct.
The trade-off worth naming is that make a nice-to-have fail, assert the page renders with a banner, and assert a write still fails honestly, so degradation is correct adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
Sources
Sources: Graceful degradation, stale-while-revalidate.
FAQ
- Cache or compute a default?
- A stale cache is usually the best fallback for read-only widgets, because it is close to right; a computed default is for when you have no cache at all.
- Should I degrade writes too?
- No; a degraded write that silently succeeds is a data loss bug. Queue the write and tell the user it is pending, or fail it honestly.
Report a problem with this articleOpens a pre-filled issue on GitHub.