Serving
Continuous batching
A scheduling style that admits a new request the moment an old one finishes. It keeps decode slots busy and raises how many tokens a GPU returns per second.
Early serving stacks filled a fixed batch of requests, ran them to the end, and only then started the next batch. That was fine for image generation, where every request does similar work. Text requests are nothing like that: one user asks for a two-line summary and another pastes a document and asks for an essay. A batch that started together must wait for its slowest member, so the slot holding the short reply sits idle while a long generation crawls along.
Continuous batching fixes the unit of scheduling. Instead of "start a batch", each decode slot is refilled the instant it empties, inside the forward pass. New requests join mid-batch, finished requests leave mid-batch, and the GPU keeps its whole batch dimension busy nearly all the time.
The cost is a more complex scheduler: the server has to copy new requests in and out of the running state, manage memory so late joiners and the KV cache coexist, and decide what to do when it runs out of room. That is the practical interview territory, because the two failure directions are opposite: admit too eagerly and everyone suffers through preemptions and re-queues, admit too slowly and the GPU idles while demand queues up.
It is useful to name what it does to the two metrics you care about. Aggregate tokens per second rises a lot, because every slot is busy. But per-user tokens per second can fall slightly under load, since more users share the same bandwidth. The honest framing: continuous batching trades a small latency tax per user for a large throughput gain per GPU.
A worked example
A server with 8 decode slots, 40 tokens per second per slot, responses averaging 500 tokens, watched over a 25 second window in which the longest request needs all of it.
- Capacity in the window: 8 slots x 25 s x 40 tokens/s = 8,000 generated tokens.
- Static batching runs one group of 8 to the end: 8 responses, and any slot whose request finished early does nothing for the remainder.
- Continuous batching keeps every slot generating for the full window: 8,000 tokens of output.
- At 500 tokens per response, 8,000 tokens of output is 8,000 / 500 = 16 completed responses instead of 8.
Same GPU, same 25 seconds, roughly twice the completed requests, because no slot idles waiting for a straggling response to finish.
Where this shows up
- Design ChatGPT: Tiers & Rate LimitsDesign ChatGPT is the most-cited systems design question at AI companies, and it is really one question: when everyone arrives at once, who gets served, who waits, and who is told no, all without the paying tier ever noticing. The answer interviewers grade against has three parts. First, three pools: a small provisioned pool whose cards exist for one tier only, a larger shared pool where paid requests carry priority over free ones, and the queue itself, which lives in card memory, not in a message broker. Second, a token-bucket rate limiter at the gateway, held in Redis for atomicity under concurrent writers, that admits free arrivals at a chosen share of demand and reconciles the token count after each grant, so a burst of arrivals is answered instantly without consulting a GPU. Third, shedding: a request refused at the gateway with a 429 costs nothing; the same request admitted into a saturated pool holds an expensive seat and lengthens every wait behind it, which is why the tail wait punishes utilization non-linearly, and why an incident that removes 30% of capacity can turn a 97 millisecond paid wait into an 850 millisecond one. Interviewers test this because every knob in the design is a money or trust decision: renting burst capacity for a launch day, tightening the bucket over a jammed pool, or letting the free tier shed so the subscribers do not notice an outage. The three challenges below work the mechanics: the admit count a token bucket grants, the queue wait the utilization formula quotes, and the shed arithmetic that keeps the shared pool from jamming.
- LLM Serving InternalsBefore a streamed answer reaches the screen, a scheduler admits the request into a batch of others running on rented GPUs, decides when its prompt gets read, and keeps it fed token by token until the answer finishes. Serving is that layer, and it runs on arithmetic that is unforgiving. Decode, the steady writing of the answer one token at a time, is bandwidth bound: every step re-reads the model's weights from card memory whether the batch holds one request or sixty, so a pool serving one request at a time pays its most expensive constant for a single token. Batching is the fix, sharing that read across every request running at once, which is why aggregate throughput climbs almost free as the batch grows. The resource that bounds the batch is not compute but memory: the KV cache, the per-request scratch space the model keeps so it can continue each prompt, grows with every layer and with sequence length, and when it fills, the batch size dial quietly stops mattering while the rest of the traffic waits. Prefill, the reading of the prompt that produces that scratch space, is compute bound and costs about 2 FLOPs per parameter per prompt token, which is why two requests sharing a cached opening start dramatically faster than two strangers. Interviewers test this material because the numbers decide the architecture: whether to rent dedicated cards sized for a peak, paid by the hour whether busy or not, or pay per token on a shared pool; how many cards a model swallows for its weights alone before a single seat exists; and why the tail, the p95 wait experienced by the slowest request, is what the service level agreement actually measures. The coding version of this topic is real: an xAI onsite round asks candidates to implement a simplified inference engine, meaning request batching, per-batch inference, and token-level result collection, and other labs ask the design version, batching requests up to a fixed size or a wait cap, whichever comes first. The three challenges below work the core arithmetic: the bytes one cached token occupies, the seats a card's free memory can grant, and the seconds prefill spends before the first token exists.
- Serving AI ReliablyThe AI feature launched ten days ago and is the quietest thing you operate: the dashboard is a strip of green graphs, no complaints, nothing shipped this week. Then at 3am something changes, and running this feature is different because the dependency is a model you neither wrote nor can restart: a provider answers your users, and the provider can change its capacity, its pricing, or the model itself without telling you. So the board grows meters that watch the call rather than your code. p95 latency, the wait that 95 of every 100 requests stay under, catches a capacity squeeze that the median wait, p50, smooths right over. The error share catches a rate limit, a provider ceiling on how many calls fit in a minute that a launch surge can trip with zero code changes. Daily spend catches a prompt edit that quietly broke the prefix cache, the discount a provider grants while your requests resend the same opening text. And an eval set, a small fixed list of prompts with expected answers that your code reruns on a schedule, catches the scariest one: a silent quality drop after the provider swapped the model, the failure users notice and no latency meter ever blinks. What you do about it is the fallback ladder, an ordered list of answers to serve while the model misbehaves: retries with backoff first, then a smaller or older model, then a cached reply, ordered so the user meets slow long before they ever meet gone. Pinning, writing the exact model version into your config instead of floating on the provider default, is what turns a swap back into a rollback. Interviewers ask what you watch and what you do at 3am: a specific ladder is the answer of someone who ran a live AI feature, and we would monitor things is the answer of someone who has not. The three challenges below grade exactly that: the order you triage a crowded alert board in, the p95 and eval math that tells you to roll a model version back, and the share counters that say whether the ladder is holding.