Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

Fallbacks
HLD

Fallbacks

The plan-B for every call — designing alternate answers before you need them.

Every Call Needs a Plan B

 any remote call can fail: timeout, error, circuit open.

 code without a fallback:
   recs = recommendationService.get(user)   ← throws?
   page dies with it.

 with fallback:
   try:    recs = recService.get(user)
   catch:  recs = popularItemsCache.get()   ← plan B, always ready

 the fallback is chosen AT DESIGN TIME,
 per call, by asking: "what's an acceptable answer
 when this dependency is absent?"

The Fallback Taxonomy

TypeExampleFreshness
Cached valuelast-known recommendationsstale but relevant
Default/statictrending list, generic contentimpersonal
Alternative sourcesecondary provider, read replicanear-current
Computed approximationestimated delivery datehonest-ish
Empty-but-validhide section, empty listclean
Queued deferral”will process shortly”delayed not lost
 ordering principle: prefer CLOSER-TO-TRUTH fallbacks;
 degrade to defaults only as needed. cache-first ladders:
   live → short-cache → long-cache → static default → omit

Fallbacks That Lie Are Bugs

 integrity rules from degradation apply per-call:

 ✗ payment gateway down → fallback to "mark paid"
   (never! queue + retry + visible pending instead)
 ✗ inventory timeout → assume in-stock silently
   ("usually right" corrupts trust when wrong at checkout)
 ✓ shipping estimate timeout → show RANGE with "estimate" label
 ✓ fraud-service down → allow + flag for async review
   (risk-ACCEPTANCE decision, made consciously)

 every fallback is a RISK DECISION.
 money/identity/legal claims: fail visibly.
 content/convenience: degrade freely.

Engineering the Pattern

 □ WRAP AT THE CLIENT: resilience library or generated client
   applies fallback uniformly; business code stays clean
 □ FALLBACK METRICS: track fallback-rate per dependency —
   sustained elevation = incident signal (users on plan B
   while dashboards look "fine")
 □ EXPIRE THE CRUTCH: cached fallbacks carry age limits;
   week-old "recommendations" become noise
 □ TEST THE PLAN B: chaos-drill dependencies OFF and verify
   fallbacks engage correctly (they rot otherwise!)

Interview Framing

“Walk me through your design’s behavior when each external call fails” scored shape: per-dependency fallback table (dependency → plan B → staleness/risk class), explicit integrity boundary sentence, fallback-metrics observability, chaos-testing note. Interviewers probe exactly this because designs are judged by their worst-day behavior, not their happy-path diagrams — have the table ready before they ask.

My Private Notes

Notes are auto-saved locally to this device.