Llm Gateway Cost And Caching hard
The client SDK retries failed calls 3 times, and the gateway also retries each upstream call 3 times. The provider becomes overloaded and returns 429s and timeouts. What happens, and what is the right fix?
- A One user request can become up to 16 provider attempts, deepening overload; retry at a single layer with a budget, jitter, and Retry-After.
- B Retries are harmless because rejected 429 calls are never billed, so the only cost is latency; raising retry counts improves the success rate.
- C Remove gateway retries and fail over to the cheapest provider on the first error, since a different provider never experiences correlated load.
- D Add an idempotency key to every call so the provider deduplicates retried prompts and bills them once, which makes layered retries safe.
Answer: A. One user request can become up to 16 provider attempts, deepening overload; retry at a single layer with a budget, jitter, and Retry-After.
Layered retries multiply: 4 client attempts times 4 gateway attempts is up to **16 calls** per user request, arriving exactly when the provider has the least capacity. A single retry layer with a retry budget and backoff accepts a lower success rate during overload in exchange for faster recovery. Rejected 429s cost little (B), but timed-out calls may still be processed and billed, and most LLM APIs do not deduplicate generation calls by idempotency key (D).
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- Your primary LLM provider is fully down for an hour, and no tested fallback exists for your agent feature. The product also has an FAQ answer feature backed by a semantic cache. What is the best degradation mode?
- Your gateway applies one 5-second timeout to all LLM calls. Classification calls work fine, but long streamed answers are frequently cut off. What is the best fix?
- A multi-tenant B2B support assistant answers questions using each customer's private knowledge base. To raise the semantic cache hit rate from 22% to 35%, an engineer proposes one shared cache across all tenants. What is the main problem?
- During a provider brownout returning 429 and 503 errors, the client SDK retries 3 times and the gateway also retries 3 times, both immediately. Provider load spikes, and the bill grows from partially streamed responses. What should you change?
- Finance asks for LLM spend broken down by tenant and by product feature. Today the gateway only sees the total on the provider's monthly invoice. What should you do?
- A retail assistant uses a semantic cache. Weeks after a store changed its holiday hours, users still receive the old hours from cached answers. What is the right fix?