KatInterview

Build a Request Batching System for LLM Serving

System DesignModel answer
HardModel answerSystem Designbatchinginferencelatency

Last updated

Design an inference service that groups incoming LLM requests into batches, assuming 100ms processing per batch, with attention to queueing, routing, and failure modes.

You're building a service that handles inference for a large language model. Clients submit prompts and wait for generated responses. Rather than processing requests individually, your service collects pending requests into groups and processes each group together to maximize hardware utilization.

Given constraint: Assume processing one group takes exactly 100 milliseconds.

Design the complete request flow—from when a client submits a prompt through returning the generated text—including your grouping strategy, capacity planning, result distribution, and error recovery. Clearly state what activities the 100ms includes and excludes.

What to Address

  • How requests move from arrival to processing and back to clients
  • Your policy for forming groups (triggers, size limits, timing)
  • Calculating how many processing units you need
  • Routing individual results from a group back to the correct waiting clients
  • Handling worker crashes, problematic requests, and overload

Parameters to Consider

You may ask about these or state reasonable assumptions:

  • Expected request rate and target latency (first token vs. complete response)
  • Maximum group size the hardware supports
  • Whether you have one model or multiple that cannot share groups
  • Streaming vs. complete response delivery
  • Prompt and response length distributions

Hints

Hint 1

Break down total latency into stages: network, waiting for group formation, processing, and return path

Hint 2

Consider both time-based and size-based triggers for closing a group

Hint 3

Challenge the fixed 100ms assumption—what real-world factors would make batch time variable?