KatInterview

Design a Low-Latency LLM Inference Gateway

System DesignModel answer
MediumModel answerSystem Designsystem designLLM servinginference

Last updated

Design a production gateway that routes, batches, and serves LLM inference requests at scale with low latency and high throughput.

Scenario

Your company runs a B2B SaaS product that embeds an AI assistant into third-party applications. Customers send chat completion requests (think: a /v1/chat/completions style API) to your platform, which routes them to one or more large language models you host internally on GPU clusters.

You are asked to design the LLM Inference Gateway — the layer that sits between external clients and the raw model servers.

Scale & Requirements

Functional requirements

  • Accept streaming and non-streaming chat completion requests
  • Support multiple models (e.g., a 7B, a 70B, and a 405B parameter model)
  • Enforce per-tenant rate limits and quotas
  • Return token-by-token streaming responses (SSE/WebSocket)

Non-functional requirements

  • P50 time-to-first-token (TTFT) under 500 ms, P99 under 2 s
  • Throughput: sustain 5,000 requests per second (RPS) at peak
  • At least 99.9% availability
  • Cost efficiency: GPU utilization should stay above 70% during business hours

What is expected

Walk through:

  1. API design — what does the external-facing contract look like?
  2. Architecture — what are the major components and how do they interact?
  3. Request routing and batching — how do you decide which model server handles a request?
  4. Streaming — how does token-by-token output flow back to the client?
  5. Key deep dives — at least two of: rate limiting, continuous batching, KV-cache management, autoscaling, or fault tolerance
  6. Trade-offs — where did you make explicit choices and what did you give up?

Hints

Hint 1

Start by separating the gateway's concerns from the model server's concerns — the gateway should be stateless so it scales horizontally, while the model server manages GPU state (KV cache).

Hint 2

Continuous batching (also called iteration-level scheduling) is the key technique that keeps GPU utilization high without sacrificing latency — explain how it differs from static batching.

Hint 3

Streaming over SSE requires the gateway to hold open long-lived connections; think about what this means for connection counts, load balancer timeouts, and back-pressure.