Design an LLM Inference Service
Design a multi-tenant service that serves LLM completions to millions of concurrent requests across a fleet of GPUs. Clients send prompts and receive generated tokens back, either streaming one token at a time or batched into a single response. The service runs multiple model sizes (7B to 400B parameters), balances GPU utilization via continuous batching, manages KV cache across requests, supports speculative decoding and quantization, routes requests to the right model tier, and enforces per-tenant SLOs and cost budgets. The hardest constraints are latency sensitivity (time-to-first-token under 500ms p50), GPU cost (GPUs are 10-100x more expensive than CPUs), and the tight coupling between scheduling decisions and model-level mechanics like attention computation.
Suggested time: 90 minutes
Loading the workspace...
About this problem
An LLM inference service takes a prompt plus sampling parameters and streams generated tokens back to the client. On the surface this looks like any other stateless web API. It is not. The work per request is measured in GPU-seconds rather than milliseconds, the hardware is 10 to 100 times more expensive per hour than CPUs, and a single distracted scheduling decision can leave a 40K dollar accelerator idle. Every requirement we write has to be read through that lens.
What your design needs to cover
Completion API
Multi-model serving
Function calling and structured output
Long context
Per-request cost and usage
Learn from other designs
Concepts used in this design
The building blocks this design relies on, each explained in its own lesson.
Related problems
Design a Domain Name System (advanced)
Design a Load Balancer (hard)
Design a Multi-Cloud API Gateway (advanced)