The interview problem
Serve a shared language model to multiple customers with streamed output, bounded cost, cancellation, and predictable time to first token.
Original practice question. Relevant to AI infrastructure roles; not a verified interview question from OpenAI, Anthropic or xAI. Reviewed September 26, 2026. All workload numbers and acceptance thresholds below are illustrative practice assumptions.
1. Define the unit of work
Clarify model size, hardware, prompt-length distribution, output caps and tenant priorities. Requests/second alone is inadequate: a short prompt and a 100,000-token prompt consume very different resources. Define time to first token, inter-token delay, total completion latency and useful completed requests under load. Measure percentiles by workload class.
Use a 45-minute outline: requirements for 5 minutes, token and memory calculations for 8, serving path for 12, scheduling and failures for 12, then trade-offs for 8. Start with a managed inference backend unless the question specifically requires owning GPUs.
2. Admit before allocating expensive state
POST /generations includes a request ID, model version, input, output-token limit and deadline. Authenticate, enforce tenant budgets and bound input size before queueing. Persist request status and chargeable usage separately from transient token buffers. An idempotency key may return an existing request status; it does not promise deterministic regenerated text.
The router selects a healthy replica with the requested immutable weights and tokenizer. The scheduler handles prefill, which processes the prompt, and decode, which generates additional tokens. Continuous batching adds and removes sequences between execution steps. Chunked prefill can reduce long-prompt interference, but its actual benefit must be benchmarked against the workload. Separate prefill/decode pools only after demonstrating that benefits exceed KV-transfer and operational costs.
3. Work a token and memory budget
Suppose 20 requests/second produce 200 output tokens each: demand is 4,000 output tokens/second. A measured replica capacity of 800 output tokens/second at the chosen latency target implies at least five replicas with no headroom. At 70% planned utilization, ceil(4,000 / (800 × 0.7)) = eight replicas. This is a planning approximation: the benchmark must include the real prompt distribution and prefill load.
For a toy architecture with 32 layers, 8 KV heads, head dimension 128 and two-byte cache values, KV memory per token is 2 × 32 × 8 × 128 × 2 = 131,072 bytes. An 8,192-token sequence needs 1 GiB of KV storage before allocator overhead. Model weights, activations and runtime buffers consume additional memory. Cache layout and parallelism change per-device accounting, so never equate total GPU memory with usable token capacity.
4. Protect latency and handle partial output
Bound queued tokens and active sequence memory, isolate bulk jobs, and reject or defer requests before overload causes universal timeouts. Autoscaling must account for model loading and warm-up; it cannot instantly absorb a spike. Prefix caching can save repeated prefill but requires exact compatible model/tokenizer inputs and an explicit tenant-isolation policy.
Each streamed event has a request ID and sequence number. On cancellation, remove scheduled work and release its cache blocks promptly. A disconnect may happen after the client saw only part of the output. Support replay only if token events were durably buffered; otherwise expose partial/failed status and make a new generation explicit. Do not silently splice a regenerated suffix into a previous response.
5. Compare architectures with the same workload
A larger batch can increase throughput while worsening inter-token latency. Shorter output caps reduce cost but may hurt task success. A smaller fallback model changes quality, so make fallback visible in the response contract. Benchmark long/short prompt mixtures, cancellation storms, replica failure, and a single tenant monopolizing cache memory. Record completed useful work and rejection rate alongside latency.
6. Practice and self-review
Foundation: distinguish prefill, decoding and KV cache. Senior: explain why five replicas cannot safely serve the illustrative demand at full utilization. Staff: defend colocated versus disaggregated serving while accounting for cache transfer, network failure and model rollout.
Score 0–2 each for workload definition, correct memory arithmetic, scheduling fairness, partial-stream semantics and a measurable quality/cost trade-off. Two points require a mechanism and limitation. A fast tokens/second figure without a latency target or prompt distribution earns no capacity credit.
Sources and next steps
References support the underlying concepts; the proposed architecture, exercises, and rubric are our own. Start with general model serving or review attention and serving trade-offs.
Continue your preparation
Choose a connected learning path or browse more ML system design questions. Read our editorial method and attribution policy.