Serving
Request queueing
Requests line up when they arrive faster than the server admits them. Queue depth warns that capacity is short, and it shows before GPU metrics do.
When requests arrive faster than the server can admit them, they wait in a queue - and the queue is where the user's latency goes before anything on the card even moves. Servers queue on purpose: admitting beyond the KV cache capacity causes preemption and recomputation, which is slower than waiting, so a bounded queue plus an admission limit is the honest design.
The size of the wait is tractable arithmetic, not mystery. Little's law ties the number of requests resident to the arrival rate and the time each request spends inside: arrival rate times sojourn. Queue depth therefore warns early - it grows when arrivals outpace service, before GPU gauges look busy and long before the SLO breach reports.
The fixes are ranked by how much they cost. Shed load early with a clear rejection instead of letting every user absorb a growing wait; move work that is not latency-critical out of the interactive queue; add replicas when arrival rate stays above what admission allows; and route or batch smarter when the problem is scheduling rather than raw capacity. What you must not do is admit everything and let the cache sort out the casualties.
A worked example
A server receives 10 requests per second on average, and each request spends 0.5 s from arrival to completion inside the server. Measured p95 wait runs about twice the average.
- Little's law: requests resident = arrival rate x time spent = 10 x 0.5 = 5 requests in the system.
- If arrivals double to 20 per second against the same 0.5 s of service, the resident count climbs toward 10 and wait times grow with it.
- At the doubled arrival rate the queue drains only if the server cuts sojourn time below 0.05 s per request - so capacity, not luck, has to change.
Queueing is arithmetic, not mystery: arrival rate times sojourn time says how many requests are resident, and a rising depth is the capacity warning.
Where this shows up
- 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.