KatInterview

Design an LLM Inference Gateway with Request Batching

System DesignModel answer
MediumModel answerSystem Designsystem designLLM servinginference

Last updated

Design a production gateway that receives streaming LLM requests, batches them efficiently, routes to GPU backends, and handles autoscaling under bursty traffic.

Scenario

Your company offers a developer API that lets third-party applications call a self-hosted large language model (7B–70B parameter range). Traffic is bursty: calm during nights, spiky during business hours, with occasional viral bursts 10–20x above the baseline. Latency SLAs matter — customers care about time-to-first-token (TTFT) and total generation time.

You currently run a few GPU servers but have no serious infrastructure between the caller and the model process. The on-call engineer keeps getting paged because queues overflow or cold GPUs serve the first tokens slowly.

What you are expected to design

Design an LLM Inference Gateway that sits between API callers and GPU backends. Your design should address:

  1. Requirements & scale — clarify functional and non-functional requirements; propose concrete numbers.
  2. API contract — what does the gateway expose to callers? What does it expose to backend workers?
  3. Data model — what state does the gateway need to track per request?
  4. Core architecture — components, data flow, how continuous batching works at a high level.
  5. Autoscaling — how do you scale GPU workers up and down without dropping requests?
  6. Deep dives — pick at least two: token streaming to the caller, request prioritization, cost-aware routing, handling very long contexts.
  7. Trade-offs — discuss at least two meaningful design decisions where reasonable engineers could disagree.

Constraints / assumptions you may state

  • You may use any cloud or open-source components.
  • The model weights are already loaded on each GPU worker; cold-start is 2–4 minutes.
  • You do not need to design the model itself or training infrastructure.
  • One GPU worker can serve one or more requests simultaneously via continuous batching.

Hints

Hint 1

Start by separating concerns: the gateway is a CPU-bound routing layer; the GPU worker is compute-bound. Keep them independently scalable and think about what state must live where.

Hint 2

Continuous batching (iteration-level scheduling) is the key technique that lets a GPU interleave tokens from multiple requests — contrast it with static batching to show you understand the trade-off.

Hint 3

For streaming, think end-to-end: the GPU emits one token at a time, the gateway must fan it out to the right HTTP/SSE connection. Where can you lose tokens? Where can you buffer too aggressively?