Why this matters
Model APIs time out, rate-limit, overload, change behaviour and occasionally return garbage. Your product must keep working (or fail honestly) through all of it. This builds directly on 3.8 Resilience patterns.
Q12. Provider times out, returns 429, or returns garbage?
| Failure | Response |
|---|---|
| 429 / 5xx / timeout / network | Retry with capped exponential backoff + jitter; Retry-After wins (capped); bounded attempts and a total deadline |
| Persistent failures | Circuit breaker opens; route to a validated fallback provider |
| 400 / 401 / 422 / policy | Never retry: it only repeats the cost. Fail fast, alert |
| Schema violation | Not transient. One bounded repair for low-risk tasks, else fallback or human queue |
| Everything down | Degrade honestly: queue, cached answer, non-AI path. Never fabricate |
Casebook evidence: an HTTP layer that retries only network errors, 429 and 5xx, capping Retry-After at 30 s (P1); a CLI that stops after three consecutive model failures, a simple circuit breaker (P5); an app mapping each failure to its own status code (P2). Code: C1.
Q16. Rate limits?
Per-user and per-tenant quotas, concurrency caps, a Redis token bucket on TPM as well as RPM, queues for non-interactive work, provider-aware backoff. Return 429 with Retry-After to your own clients (for example 20 evaluations per hour per user, P2).
Timeouts for streaming calls
Use three: connect (a few seconds), time to first token (catches stuck generations early), and total (bounded by what the user will wait). A single long total timeout hides stuck requests.
Never pay twice
Save the raw paid reply before parsing; write outputs atomically ("whole or not at all"); a failed write marks the item failed rather than crashing the batch; refuse to re-send finished items. Resuming after an outage then costs nothing extra.
Honest degradation
When no validated model is available: queue the request and tell the user when to expect it, serve a cached answer clearly marked as such, or fall back to the non-AI path (a search, a form, a human). Never invent an answer to look available.
Common mistakes
- Retrying 400s and policy refusals.
- Falling back to an unevaluated model.
- Retries stacked at the SDK, service and gateway levels.
- A single generic error for every failure, which hides outages (S2).
Interview follow-ups
- "The provider is degraded but not down: slow, occasional errors." Latency-based breakers (trip on p95 over a threshold), hedged requests for idempotent reads, or route a share of traffic to the fallback, all watched on the dashboard.
- "How do you test the fallback path?" Unit tests with fake failing providers, plus a scheduled game day that forces fallback in staging and checks eval quality on the fallback model.
Check yourself
A reply fails schema validation. Retry?
It's not a transient error, so not a blind retry. For low-risk tasks, one bounded repair attempt (send the validation error back); otherwise a validated fallback provider or a human queue. Log it as a schema violation for the dashboard.
Why limit tokens per minute and not only requests?
Cost and provider limits scale with tokens. One request with a huge context can cost as much as hundreds of small ones and exhaust the provider's token quota for everyone.
Build it
Implement C1 with two fake providers (one flaky, one slow) and tests for every row of the Q12 table.