TensoriumInterview preparation
← Learn

System design · inference & serving

High-throughput model inference

A GPU can be busy while your service still misses its latency target. Learn how admission, compatible batching, bounded queues, and response routing work together, then assemble the request path yourself.

Start with independent text-embedding requests; then contrast the design with autoregressive LLM serving. No model execution or external service required.

1 · Start with the contract, not the GPU

Our service embeds independent text requests with one fixed model version. Tokenization assigns compatible length/shape buckets before batching. Design for sustained admitted throughput while keeping p95 end-to-end latency within an explicit product budget. Record request IDs, deadlines, cancellation, and model version. There is no universal best batch size.

2 · Amortize work, but do not hide the waiting

One request per forward pass can waste parallelism and repeatedly pay launch overhead. Group compatible requests so one forward pass serves several callers. Dispatch when the batch limit is reached or the oldest request reaches its batching deadline, subject to worker availability. The batching-delay setting is not an end-to-end latency guarantee: a busy worker can create additional waiting.

3 · Capacity needs a bounded queue

If arrivals exceed service capacity, a larger queue postpones failure rather than fixing it. Bound admission and pending work, expire requests that can no longer meet their deadline, propagate cancellation, and use retry budgets with backoff. Scale replicas only when the bottleneck and memory budget justify it. More workers do not fix a saturated CPU tokenizer or an overloaded downstream consumer.

4 · Know when this abstraction breaks

Dynamic batching works naturally for independent forward passes such as embeddings or image classification. Autoregressive generation also retains per-request KV state: continuous batching admits and retires sequences between iterations. Its scheduler must budget tokens and KV memory, not just request count; long prefills can interfere with decode latency. The builder below intentionally models the simpler single-forward-pass case.

Build the design

Assemble a request-batching pipeline

Use each component once. Drag from the component bank into the pipeline, then reorder from top to bottom. For this exercise, admission precedes preprocessing, shape compatibility is known before queueing, and responses return only after execution.

Keyboard: focus a drag handle, press Space to pick up, arrows to move, and Space to drop. Add, move, and remove buttons also work without dragging. Session-only workspace; edits reset when you leave or reload.

Component bank · 6

GPU worker

Run one model forward pass over the assembled batch.

Bounded request queue

Hold tokenized requests with IDs, arrival times, and deadlines.

Response router

Split batch outputs and return each result to its original request ID.

API gateway

Validate requests, assign IDs, and enforce admission limits.

Dynamic batcher

Group compatible requests up to a batch-size limit or a waiting deadline.

Tokenizer & shape bucketing

Prepare tensors and label compatible model, shape, and length buckets.

Request flow: top → bottom · 0

Drop components here. Top to bottom is request-flow order.

Defend the design with numbers

Assume a compatible batch of b requests takes t(b) = 5 + 2b ms on one worker. These are chosen teaching costs, not GPU measurements. At continuous full occupancy, b=1 gives 1/0.007 ≈ 143 requests/s; b=8 gives 8/0.021 ≈ 381 requests/s. The gain comes from sharing the fixed 5 ms cost, but individual GPU execution grows from 7 to 21 ms, even before queueing.

Full-batch capacity ≈ batch size / forward-pass time
End-to-end latency = admission + preprocessing + queueing + GPU + return
Little’s law (stable system): mean in-flight = admitted throughput × mean latency

At a stable admitted throughput of 300 requests/s and mean latency of 80 ms, expect about 24 requests in flight across the whole measured service, not necessarily 24 queued. Do not substitute p95 latency into this mean-value identity. Leave capacity headroom for bursts and validate with realistic arrival patterns and input lengths.

What to measure and what to change

  • Track admitted/completed requests/s, rejected/expired requests, queue depth/age, realized batch sizes, GPU memory, and p50/p95/p99 end-to-end latency.
  • If batches rarely fill, increasing the size limit alone does not create arrivals. A longer waiting window trades latency for grouping opportunities.
  • If queues grow while workers are saturated, bound waiting and add measured capacity. If workers are idle, inspect CPU preprocessing and dispatch overhead first.
  • For LLM generation, additionally track prefill/decode token throughput, time to first token, inter-token latency, KV occupancy, and preemption. Do not compare unlike request-length mixtures.