Lesson 18 / 27

Fallbacks and Graceful Degradation

Keep the product useful when the API is slow or down.

Plan B for every dependency

Any external API will sometimes be slow or unavailable. Decide in advance what your product does: show a clear message and let the user retry; queue the request and notify when done; serve a cached or simpler answer; switch to a secondary model or provider (keep prompts and parsing provider-neutral, and test the fallback regularly); or hand off to a human. Use a circuit breaker so that after repeated failures you stop calling for a short time instead of piling up timeouts. Monitor error rate, latency percentiles and fallback usage, and alert when they move. A graceful failure is part of the feature, not an afterthought.

Quick check: What does a circuit breaker do after repeated failures?

  • Pauses calls for a while to avoid piling up timeouts
  • Deletes the API key
  • Doubles the retries
  • Switches off logging
Answer

Pauses calls for a while to avoid piling up timeouts — Failing fast protects your system and gives the dependency time to recover.