What is Fallback?
Fallback means automatically retrying a request with an alternative provider when the primary provider fails. This improves reliability by ensuring your application continues working even if one provider experiences downtime or errors.Implementation Pattern
The approach is straightforward:- Send a request to your primary provider
- If it fails (network error, provider outage, rate limit, etc.), catch the error
- Retry the same request with a fallback provider
Multiple Fallbacks
You can chain several fallback providers for even greater resilience:Python
Best Practices
- Order by preference — place your most reliable or cost-effective provider first.
- Log fallback events — track when fallbacks occur so you can identify recurring provider issues.
- Set timeouts — add request timeouts so a slow provider triggers the fallback quickly rather than hanging.
- Handle all providers failing — always have a final error path if every provider is unavailable.