System Design · Practice problem · Medium
Stay Up When an LLM Provider Fails
Keep a second provider, try them in a set order with a timeout on the first, and decide ahead of time what happens to the calls that no longer fit once one is gone. Build that here, then break it.
Medium means two needs that pull against each other. You solve it on a canvas that runs your design. The canvas needs JavaScript; everything on this page works without it.
What is the situation?
You run the AI assistant inside a document app, and it does two jobs. In chat, a person types a question and watches the screen until the answer arrives, so POST /chat has to wait for a model, and the page gives up after 10 seconds. For a summary, a person asks for a document to be summarised and goes back to their work, so POST /summaries only has to say the job was accepted within the 5 seconds the page waits. The summary can follow a little later. You buy models from two providers. Provider A answers in about 900 ms and Provider B in about 400 ms. Each accepts 200 calls a second from your account and refuses the rest. On an ordinary day you get 100 chat questions and 20 summaries a second. When a big customer uploads a batch, summaries jump by another 180 a second for 30 seconds, so 300 calls a second want a model. Two providers have room for that. One does not. A chat answer has to come from a model. If neither provider can answer, tell the person so with an error: putting their question on a queue, or having your own server reply, is not answering it. Design the path from these two APIs to the providers.
What must your design do?
- At least 99% of chat questions are answered whenever at least one provider is up.
- Chat answers within 2.8 seconds at the 99th percentile on an ordinary day and during a batch, 4 seconds with a provider down, and 6 seconds while a provider hangs.
- At least 99.5% of summary requests are accepted.
- The oldest unfinished summary is at most 20 seconds old on an ordinary day and with a provider down at ordinary traffic, 100 seconds in a batch, 60 seconds while a provider hangs, and 90 seconds after both providers have been down.
- No Worker drops a summary.
- Your calls really reach the providers: with each provider down for 30 seconds in turn, at least 15 chat calls and 3 summary calls a second, over the whole test, reach Provider A.
- When both providers are down for 30 seconds, nothing pretends otherwise: at most 85% of chat over that test is reported answered, and the oldest summary has waited at least 25 seconds.
- The system costs $540 a month or less.
What does Run test?
Run works without an account. It checks your design against 3 tests you can read before you start:
- An ordinary hour. 100 chat questions and 20 summaries a second for 40 seconds, with both providers up.
- Each provider takes a turn going down. At second 15, Provider B went down for 30 seconds. At second 65, Provider A went down for 30 seconds. Traffic stayed at 100 chat questions and 20 summaries a second.
- A big batch. At second 20, a big customer uploaded a batch: summaries rose by 180 a second for 30 seconds, to 300 calls a second in all. Both providers stayed up.
What does Submit add?
Submit needs an account. It runs 4 more tests you cannot read in advance, and stops at the first one your design fails, showing what happened and why. Passing every test, or giving up, unlocks the written solution.
Which parts can you use?
Already on your canvas: Provider A, Provider B.
- Load Balancer: about 50,003 a second, $18 a month each
- App Server: about 2,000 a second, $45 a month each
- Queue: effectively unlimited, $25 a month each
- Worker: about 15 a second, $45 a month each
- Waiting Room: effectively unlimited, $25 a month each
Every connection takes 1 ms, and the budget is $540 a month.
What does this problem leave out?
- Tokens. A provider here limits calls a second, and a long document costs the same as a short question.
- Streaming and time to first token. A chat answer counts when the whole of it is back.
- What each provider charges per call, and whether its answers are any good. The two models are treated as interchangeable.
- A provider punishing you for being refused. Asking again after a refusal costs you nothing but time.
- A Worker crashing. No test here crashes one, so what your Queue does with work a dead Worker held is not graded in this problem.
Where does this problem fit?
Its category is Design the building block: Build the primitive itself. It practises queues & async, rate limiting & protection and reliability & ops.
By GOAT Engineer. Explore System Design · Privacy Policy · Contact.