Zenaique

Describe how continuous batching interacts with the KV cache

Short answer·Medium·4.0 · 0·~3 min·Asked atFigure AiKpmgMphasis·Relevant atAi4bharatAnthropicCerebrasDeepseek
Attempt it

Continuous (iteration level) batching changes how an LLM server schedules requests compared to static batching. Describe how requests enter and leave the batch in continuous batching, and what that implies for KV-cache lifetime and allocation per request.

Free · 2 AI evals / day
TL;DR

Continuous batching schedules at one decode step granularity, requests enter and leave each iteration, and per-request paged KV allocation frees pages as soon as a request finishes.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine a bus that waits at every stop for its slowest passenger to finish reading their book before moving on. That is static batching, the whole bus crawls. Continuous batching is like a moving walkway: passengers step on when they arrive, step off the moment they reach their destination, and new passengers fill the empty space immediately. The walkway never stops for anyone. For LLM serving the walkway is the GPU running one decode step per tick, the passengers are requests, and the trick that makes 'step on and off' fast is splitting the seat space into small reusable cushions instead of giving everyone a custom-sized bench.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Continuous batching is the request-level scheduling primitive that, together with PagedAttention and chunked prefill, powers every major 2026 LLM serving stack (vLLM, TGI, TensorRT-LLM, SGLang, LMDeploy). It replaces the older static (request-level) batching model with iteration-level scheduling, dramatically improving GPU utilization on realistic mixed-length workloads.

This deep dive walks the difference between the two scheduling models, explains how requests enter and leave the batch each iteration, traces the KV-cache lifetime implication, and ties everything back to PagedAttention as the prerequisite memory primitive that makes continuous batching practical. It also covers how continuous batching composes with the other scheduling mechanisms (chunked prefill, speculative decoding, prefix sharing) in the modern production stack.

Static batching: what fails and why

The original transformer serving model is static batching: collect N requests into a batch, run them through prefill and decode in lockstep, finish when the slowest one finishes.

How it works

  1. A batch of N requests is constructed (often N is fixed by serving framework).
  2. All N run prefill together (often padded to the max prefill length).
  3. Decode runs in lockstep: every iteration produces one new token for every active request.
  4. The batch terminates when the slowest request hits EOS or max_new_tokens.

Three failure modes

Head of line blocking. New requests cannot join until the current batch finishes. If your batch has one 2000-token-output request and 31 short ones, every new arrival waits for that 2000-token request to drain.

Slot waste from early-finishing requests. Requests that hit EOS at iteration 50 leave their slot effectively idle for the remaining 1950 iterations (in the worst case). The GPU still processes the batched matmul for those slots, but the outputs are discarded. KV memory stays allocated.

Memory waste from padding. Prefill is often padded to the longest prompt in the batch. A batch with one 4000-token prompt and 31 100-token prompts pays 4000 tokens of prefill compute per request.

Quantitative impact

On realistic mixed-length workloads (some short, some long, modeled as a heavy-tailed length distribution), static batching utilizes maybe 20-30% of the theoretical GPU throughput. The other 70-80% is wasted on idle slots, padded prefill, and head of line blocking.

Continuous batching: the iteration-level scheduling model
Per-request KV cache lifetime
Why PagedAttention is the prerequisite
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
PropertyStatic batchingContinuous batching
Scheduling granularityPer request (batch starts and finishes together)Per iteration (one decode step)
Batch compositionFixed at batch startChanges every iteration
Finished-request behaviorSlot stays idle until slowest finishesSlot reclaimed and KV freed immediately
New-request admissionWait until next batch startsJoin at the next iteration once memory available
KV cache lifetimeTied to slowest requestTied to each request individually
Memory layout requirementContiguous per-request buffers acceptablePaged KV required to avoid fragmentation
Throughput on mixed-length workloadsBaseline5-10x higher

Real products, models, and research that use this idea.

  • vLLM is the canonical 2026 production stack shipping continuous batching plus PagedAttention plus chunked prefill, used to serve Llama 4 Maverick, Qwen 3.5, and DeepSeek V4.
  • Orca (OSDI 2022) introduced iteration-level batching; vLLM productionized it with PagedAttention as the cache primitive.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow does continuous batching interact with speculative decoding?
A

Speculative decoding generates K candidate tokens with a smaller draft model and verifies them with the target model in one forward pass. Per request, the iteration produces K tokens (on accept) or 1 (on first reject). Continuous batching handles this naturally: each request's per-iteration KV growth is variable (1 to K blocks worth), the scheduler just tracks per-request progress. The two compose orthogonally, scheduling at the iteration level, generating multiple tokens per iteration.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Confusing continuous batching with chunked prefill. Continuous batching is request-level scheduling (which requests run this iteration); chunked prefill is prefill-side dispatching (how a long prefill gets sliced into iterations).

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Difference between request-level (static) and iteration-level (continuous) scheduling

  • Why static batching wastes GPU time waiting for slowest sequence

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium