Design an LLM Gateway

HardAIAPI GatewayRate LimitingStreamingCost ControlAbout 45 minutes

Design a gateway that all of a company's applications use to call large language models from several providers. It routes requests to the right model, enforces per-team budgets and rate limits, caches where it can, fails over when a provider is down, and logs usage for billing. Plan for 5,000 requests per second, most of them streaming.

How the interview goes

Five phases, and questions the interviewer is likely to ask in each.

  1. 1. Requirements

    • Which teams need guaranteed capacity?
    • Is a cached answer acceptable for every use case?
    Show a hint

    Ask what each team should experience when it reaches its budget.

  2. 2. High-level design

    • What state does the gateway keep, and where?
    • How do applications authenticate?
    Show a hint

    Keep the request path thin; push accounting off to the side.

  3. 3. Deep dive

    • How do you rate-limit by tokens when you do not know the output length yet?
    • A provider fails after 200 tokens of a stream. What does the client see?
    Show a hint

    You can reserve an estimate up front and settle the difference when the stream ends.

  4. 4. Scaling

    • How do you shard rate-limit counters?
    • What breaks at 10x concurrent streams?
    Show a hint

    Long-lived streams change how you size and build the servers.

  5. 5. Trade-offs

    • Semantic caching: worth the risk of wrong answers?
    • Central gateway versus a client library?
    Show a hint

    Failing over mid-stream and charging correctly pull in different directions.

Practice this with an AI interviewer

Write your design doc with live diagrams while the interviewer asks one question at a time and pushes on your choices. Get a scored debrief with what to study next.

Start this interview