Skip to content
Inference Academy

Batching and continuous batching interview questions

Interview questions on LLM batching: static vs dynamic vs continuous batching, why batching raises throughput, the latency cost, scheduling, preemption and batch invariance, with model answers and follow-ups.

5 questions·Model answers and follow-upsFree
Share

Batching is the single biggest lever on the cost of serving an LLM. Interviewers check that you know why it works (decode is memory-bound), why classic request batching works badly for generation, and what the scheduler in a modern engine actually does each step.

Question 1

Why does batching increase LLM throughput so much?

Model answer

Decode is memory-bandwidth-bound: each step reads every weight from HBM to produce one token per sequence, and the tensor cores sit mostly idle. If bb sequences decode together, the weights are read once and used for all bb tokens, so the expensive part of the step is shared.

Up to the point where the step becomes compute-bound (hundreds of sequences in BF16 on an H100), adding sequences adds little time per step. Throughput in tokens per second rises almost linearly with batch size while per-token latency rises only slowly.

The limits are:

  • KV cache memory: each sequence needs its own cache, so memory usually caps the batch before compute does.
  • Attention cost: attention reads each sequence's own cache and does not benefit from batching.
  • Latency: larger batches make each step a bit slower, so inter-token latency creeps up.

Likely follow-up questions

  • Sketch throughput and per-token latency against batch size. Where do the curves bend?
  • Why does batching help a mixture-of-experts model less at small batch sizes?
  • How would you serve a single user who wants maximum speed rather than many users?

Question 2

What is continuous batching and how does it differ from static batching?

Model answer

Static batching groups requests, runs them together until every sequence in the batch finishes, then starts the next batch. Because output lengths vary widely, short requests finish early and their slots sit empty while the longest one completes, and new requests wait for the whole batch.

Dynamic batching (as in classic model servers) waits a short time to collect requests into a batch, but it still runs the batch to completion, so it has the same problem for generation.

Continuous batching, also called iteration-level or in-flight batching and introduced by the Orca paper, schedules at every decode step. After each step finished sequences leave the batch and their memory is freed, and waiting requests are admitted (their prefill is run, often chunked alongside the decodes). The batch stays full, throughput rises, and new requests do not wait for unrelated long generations.

It needs two things to work well: attention kernels that handle sequences of different lengths in one batch, and a KV cache manager that can allocate and free memory per sequence cheaply, which is what PagedAttention provides.

Likely follow-up questions

  • What does the scheduler need to know at each step to decide whom to admit?
  • How does continuous batching affect time to first token under heavy load?
  • Why was static batching good enough for image classification models?

Question 3

What does an LLM engine's scheduler decide on each step?

Model answer

On each iteration a scheduler such as vLLM's or SGLang's decides:

  1. Which running sequences continue. Usually all of them, unless memory is short.
  2. Which waiting requests to admit, subject to a maximum number of sequences, a per-step token budget and free KV cache blocks. Policies include first come first served, priority classes and, in SGLang, ordering to maximise prefix cache hits.
  3. How much prefill to run, splitting long prompts into chunks so the step fits the token budget.
  4. Whom to preempt if the cache cannot hold the next token for every running sequence, and whether to recompute or swap them later.

Then it builds the batch metadata (block tables, positions, sequence lengths), launches the forward pass, samples tokens, and streams results. Engines overlap the CPU work for step t+1t + 1 with the GPU work for step tt, because at small models and large batches the scheduler itself can become the bottleneck.

Likely follow-up questions

  • What goes wrong if the scheduler admits requests too greedily?
  • How would you add per-tenant fairness to this scheduler?
  • Why are CUDA graphs captured for a fixed set of batch sizes?

Question 4

Why can the same prompt give different outputs depending on what else is in the batch?

Model answer

With greedy decoding you would expect identical outputs, but batch composition changes the numerics:

  • Kernels choose different tiling and reduction orders, or split-K strategies, depending on batch size and sequence lengths.
  • Floating-point addition is not associative, so a different reduction order gives slightly different sums.
  • A tiny difference in logits can flip an argmax between two near-tied tokens, and after that the sequences diverge.

Other sources include non-deterministic atomics in some kernels, different chunk boundaries in chunked prefill and prefix cache hits that skip recomputation.

Fixes are batch-invariant kernels that use a fixed reduction order regardless of batch shape, which some engines now offer as an option at a throughput cost. For most products the right answer is to test with tolerances rather than exact matches, and to pin batch-invariant mode only where reproducibility matters, such as evaluation or reinforcement learning rollouts.

Likely follow-up questions

  • Why is this a bigger problem for reinforcement learning than for chat?
  • How would you write a regression test for an engine upgrade given this?
  • Does setting temperature to 0 make the server deterministic?

Question 5

How do you choose the maximum batch size or concurrency for a deployment?

Model answer

Work from the service-level objective, not from the hardware maximum:

  1. Compute the memory ceiling: free memory after weights and workspace, divided by KV bytes per token, gives total cacheable tokens. Divide by the typical context plus output length for a rough concurrency ceiling.
  2. Run a load test that sweeps request rate or concurrency with a realistic distribution of prompt and output lengths, recording TTFT and inter-token latency percentiles and throughput.
  3. Pick the highest load where p95 or p99 TTFT and ITL still meet the target. This is goodput: throughput that meets the SLO.
  4. Set the engine's limits (maximum sequences, token budget) a little below that so bursts queue rather than degrade everyone.

Report the curve, not a single number, because the right operating point moves with traffic shape.

Likely follow-up questions

  • Why can raising the maximum batch size lower goodput?
  • How would the answer change for an offline batch job with no latency target?
  • Which engine settings would you tune first in vLLM?

The lesson behind these answers · 12 min · free

GPU offload, threads and batch sizes

Worked numbers, step-through diagrams and a quiz, so you can derive the answer in the interview instead of reciting it.

Read the lesson →

Articles on this topic

Related interview questions

All interview topics →