Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Compare static (request-level) batching with continuous (iteration-level) batching for LLM serving. Why does the switch deliver ~10-20× throughput in practice? Be specific about what happens at the end of a short sequence inside a batch.
Static batching holds every slot hostage to the longest sequence; continuous batching evicts finished requests and admits new ones every decode step, keeping the GPU full and lifting throughput 10-20x.
Imagine a tour bus that only leaves once everyone aboard reaches their stop. Some riders get off after one block, but their seats stay empty because the bus waits for the last passenger riding to the far end of town. The whole bus runs half-empty for most of the trip. Continuous batching is a smarter bus: the moment a rider gets off, the driver lets a person waiting at the curb hop into that empty seat. The bus is always full, so every seat does useful work the entire trip. In serving terms, each empty seat is a wasted slice of a very expensive GPU, and keeping every seat filled is what makes inference cheap enough to run as a product.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: batching as a memory-bandwidth win + static batching's head-of-line blocking + iteration-level scheduling (admit/evict per step) + paged KV dependency + scheduler costs.
| Dimension | Static (request-level) batching | Continuous (iteration-level) batching |
|---|---|---|
| Scheduling unit | Once per batch of requests | Once per decode step |
| Batch lifetime | Until the longest sequence finishes | Rolling window, sequences enter and leave each step |
| Idle slots | Short sequences leave empty slots until the batch ends | Freed slots refilled immediately from the queue |
| Effective batch size | Decays as sequences finish | Stays near the configured maximum |
| Throughput on mixed traffic | Baseline | Roughly 10 to 20 times higher |
| Scheduler complexity | Simple, run to completion | Admission, eviction, KV budget, preemption |
| KV-cache dependency | Contiguous per-request allocation suffices | Needs paged allocation to admit mid-flight |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Claiming static batching wastes compute because of padding. The real loss is idle slots: short sequences finish early and their slot stays empty until the longest sequence in the batch terminates.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.