Production operations: capacity, scaling and failure
- Production
- 45 min
- Lesson 6 of 7 in Inference engineering
- Last verified
Select text in the lesson first to keep it with your note. With the keyboard, move focus here and press the button: the note goes with the section you are reading.
In this module
On this page
Before you start
- Completed:Distributed serving, engines and hardware
- Completed:Cost and latency optimizationProduction: cost, serving and observability
You will be able to
- Plan replicas from peak load, a benchmarked per-replica capacity at the latency target, a utilization margin and a spare, and cross-check the plan with Little's law and the KV-cache budget.
- Choose autoscaling signals that lead rather than lag, account for cold start, and explain why you scale up fast and down slowly with a drain.
- Choose a routing policy (least-loaded, prefix-aware, adapter-aware, priority tiers) and say which retries are safe and what hedging costs.
- Design a benchmark that reports goodput at the target on realistic traffic, and explain why closed-loop load and a hot cache mislead.
- Work through a latency regression by symptom, alert on symptoms while dashboarding causes, and describe graceful degradation for the main failure modes.
By six o’clock the queue is five times its usual length, and the evening rush has not even started.
Someone says to start another server. Ananya checks the dashboards, which look calm, then the clock. “One takes a while to bring up,” she says.
How do you decide when to start another server, and when to leave it off?
Concept
Lessons 1 to 5 describe one replica: a model on some GPUs behind an engine. Production is many replicas, changing traffic, deploys, failures and a bill. This lesson is the operating method: how many replicas, what makes them scale, how requests find them, how to measure honestly, and what to do when it breaks.
The shape of a typical service: clients reach a gateway (authentication, quotas, rate limits), then a router that chooses a replica, then replica pools running an engine. Metrics and traces feed dashboards and an autoscaler. Weights come from object storage with a cache on each node. An external API may sit behind the pools as overflow and failover.
Why It Matters
Most production incidents in LLM services are operational: capacity that was planned from an average, an autoscaler that reacted to a signal that lags, a benchmark that never saw a bursty arrival, a deploy that emptied every cache at once. The model was fine. Interviewers use “design the serving platform” and “latency got worse, what do you do?” to see whether you reason in numbers and in failure modes.
Mental Model
A shed with a fixed number of engines and a queue. Each engine has a rated output at the promised service time, and running it near its rating leaves nothing for a burst. Lighting a cold engine takes minutes, so you light it on the signs of a coming rush, not when the queue is already out of the door. Sending visitors to the least busy engine, or to the one that already has their paperwork out, matters as much as the number of engines.
SLOs and what to watch
Set targets per traffic class, because interactive chat, agent tool loops and batch jobs want different things. A typical set: TTFT at p95 and p99, inter-token latency at p95, error rate, and goodput, the share of requests meeting both latency targets (lesson 1).
Google’s SRE book (monitoring chapter, accessed 2026-10-21) gives the alerting rule: monitor for symptoms, which answer “what is broken”, and use cause-oriented signals to answer “why”. It names four golden signals, latency, traffic, errors and saturation. For an LLM service:
- Page on symptoms: TTFT and ITL percentiles against target, error rate, goodput.
- Dashboard for causes: running and waiting requests, queue time, KV-cache utilization, prefix-cache hit rate, preemption count, batch size, input and output token rates, speculative acceptance rate, GPU memory and throttling, and finish reasons (stop, length, abort).
vLLM’s metrics documentation (accessed 2026-10-21) lists, among others, vllm:time_to_first_token_seconds, vllm:inter_token_latency_seconds, vllm:kv_cache_usage_perc, vllm:prefix_cache_hits and vllm:prefix_cache_queries, vllm:num_requests_running, vllm:prompt_tokens_total, vllm:generation_tokens_total and vllm:request_success_total labelled by finish reason. Names change between versions, so read your engine’s /metrics output rather than copying a list.
Capacity planning
- Characterize traffic: peak and daily shape of requests per second, input and output token distributions at p50 and p95, how much prefix is shared.
- Benchmark one replica on that distribution at the target latency. The result is its goodput capacity (see the benchmarking section below), not its peak tokens per second.
- , rounded up, plus spares for failures and deploys. Running at 100 percent leaves no room for bursts, so plan at about 0.6 to 0.7 (a judgment, tune it to your burstiness and cold-start time).
- Cross-check with Little’s law and the cache: , and it must fit in the KV pool (lesson 2).
Worked example (all figures illustrative). Peak 30 requests per second, 1,200 input and 250 output tokens each. Peak output rate: tokens per second. A replica (a 70B model on four GPUs) is benchmarked at 2,000 output tokens per second at the target latency.
- replicas of raw capacity.
- At 0.65 target utilization: , so 6 replicas, plus one spare: 7 replicas, 28 GPUs. At an invented 2.50 dollars per GPU hour that is about 70 dollars per hour.
- Little’s law: a request takes about 0.5 s of TTFT plus 249 tokens at 30 ms, about 8 s, so sequences are in flight; across 6 replicas, 40 each at about 1,450 tokens.
- Cache check: a replica with a 400,000-token pool (lesson 2’s 70B on four GPUs) holds about 275 such sequences. 40 is comfortably inside.
| Step | Calculation | Result |
|---|---|---|
| Peak output rate | 7,500 tokens/s | |
| Raw replicas | 3.75 | |
| At 0.65 utilization | 5.8, so 6 | |
| Plus one spare | 7 replicas, 28 GPUs | |
| Sequences in flight | about 240 | |
| Per serving replica | about 40, inside a 275-sequence cache |
If the same plan needed 150 sequences per replica, the cache would have been the constraint, not compute, and the replica count would have to rise or the context shrink. Always check both.
Autoscaling
Signals that lag or mislead. CPU is irrelevant to GPU work. GPU utilization can read high while the replica is saturated or preempting (lesson 2), so it cannot tell you whether to add capacity.
Signals that lead. Queue depth and waiting requests, KV-cache utilization, running sequences per replica against the benchmarked limit, TTFT p95, and tokens per second against benchmarked capacity. Scale on a signal that moves before users feel it.
Cold start is the constraint. A new replica must pull a container image, load weights, capture CUDA graphs and warm up (lesson 3). Weight loading is plain arithmetic: 140 GB of weights at an assumed 2 GB/s is 70 seconds; at 10 GB/s it is 14. vLLM supports a Run:ai Model Streamer that reads tensors concurrently and streams them to GPU memory from local disk or object storage, and its documentation says distributed streaming can significantly improve load times from object storage or fast network file shares. Other mitigations: pre-pulled images, weights cached on local disk, warm pools, and minimum replicas for latency-sensitive tiers.
Worked example: traffic doubles at 9 a.m. from 30 to 60 requests per second. Each replica serves requests per second at target, so the 6 serving replicas serve 48 (the spare is held back for failures and deploys). The shortfall is 12 requests per second. If a new replica takes 3 minutes to come up, requests queue, and the last one waits seconds, worse than any latency target. Reactive scaling on a lagging signal cannot fix this. Scale ahead of the known ramp, hold a warm pool, or shed load during the gap.
Scale up fast, scale down slowly. Scale-in must drain: stop sending new requests, let open streams finish, then terminate. Long generations make draining slow, so set a maximum generation time. Scale-to-zero suits rarely used models only if users tolerate the cold start; otherwise share GPUs or use multi-adapter serving (lesson 5).
Routing
- Least loaded, not round-robin. Requests differ in cost by 100 times, so equal counts are unequal work. Use queue depth or cache usage.
- Prefix-aware routing. Hash the shared prefix so related requests reach the replica that holds the cached blocks (lesson 2), balanced against hot spots.
- Session affinity for multi-turn chats; adapter-aware routing to replicas that already hold the adapter.
- Priority tiers. Separate pools or queues for interactive and batch traffic, with reserved capacity.
- Model routing. Send easy requests to a small model and hard ones to a large one; evaluate the router itself, because its errors become your quality errors.
- Retries. Retry only failures that are safe: before the first token has been sent, for idempotent calls, with deadlines propagated and jitter added. Retry storms turn a brownout into an outage.
- Hedging sends a second copy of a slow request to another replica. Dean and Barroso (2013) discuss tail-tolerant techniques for services where rare slow responses dominate. For an LLM replica every copy is expensive GPU work, so hedging doubles load for the hedged share; use it sparingly, if at all.
Benchmarking without fooling yourself
| Mistake | Better practice |
|---|---|
| Fixed prompt and output lengths | Sample realistic distributions from production traces, including the long tail |
| Closed loop with N clients | Open loop: arrivals at a set rate (a Poisson process), so queues, saturation and tails show up |
| Reporting only averages or peak throughput | Report TTFT, ITL and end-to-end latency at p50, p95 and p99, and goodput at the target, across several load levels |
| No warm-up | Discard warm-up; measure steady state; test cold start separately |
| A hot prefix cache by accident | Control hit rate explicitly and measure with and without |
| Comparing engines at different precisions | Hold hardware, precision, maximum length and sampling fixed, and check output quality |
Why closed loop misleads: with N clients that each wait for a reply before sending another, the offered load falls automatically when the server slows. A server with a capacity of 8 requests per second and a closed loop of 64 clients will happily report 8 requests per second and a long but stable latency. An open-loop test at 10 requests per second would show the queue growing without bound. The first looks fine; the second matches what real users do.
vLLM’s benchmark tool (accessed 2026-10-21) generates finite-rate arrivals as a Poisson process by default, accepts a concurrency cap, reports p99 for TTFT, TPOT and ITL, and supports ShareGPT, random and custom datasets. Its documentation warns that repeated runs against one server can reuse prefix-cache entries and inflate throughput; vary the seed, restart, or use the sweep mode that resets caches. The number that matters is goodput at your target, on your traffic, not peak tokens per second on a synthetic run.
Debugging “latency got worse”
Method: reproduce, compare with a baseline, bisect the change, profile with engine metrics and a GPU profiler, fix, and add a regression test or alert. A classic case: a feature prepends the user’s name to the system prompt, TTFT and cost rise, and the cause is a prefix cache that no longer matches (lesson 2). Move dynamic content to the end.
Failure modes and graceful degradation
| Failure | Symptom | Mitigation |
|---|---|---|
| Out of GPU memory | crashes on long prompts | cap input and output length, leave memory headroom, quantize the cache, admission control |
| Preemption storm | high utilization, falling goodput | cap concurrency, add replicas, shorten context |
| GPU fault or hung kernel | stuck requests, an unhealthy node | health check that generates a token, not just returns HTTP 200; cordon and replace |
| Tensor-parallel peer failure | the whole replica group stalls | watchdog timeouts, restart the group |
| Slow or dropped clients | zombie sequences | cancel on disconnect, per-request timeouts |
| Thundering herd after a deploy | cold caches, long queues | gradual rollout, warm pools, rate-limited retries |
| Bad rollout | silent quality or speed regression | canary and shadow traffic, an evaluation gate, automatic rollback |
| One tenant hogging capacity | others starve | per-tenant quotas, fair scheduling, separate pools |
| Region or provider outage | errors | multi-zone or region, API fallback with the same prompt contract |
Degrade on purpose: shed low-priority load, cut maximum tokens, switch to a smaller model, serve cached answers where valid, and return a clear 429 or 503 with a retry hint. For multi-tenant services also scope prefix caches to a tenant (a cache salt, lesson 2), redact prompts in logs, and limit tokens and concurrency per key.
Cost levers, ranked
- Raise utilization: right-size replicas, batch better, consolidate pools, move batch work to off-peak.
- Prefix caching and prompt design: static prefix first, trimmed context.
- Quantization validated by evaluation (lesson 3).
- A right-sized model: route easy traffic to a smaller one.
- Spot or preemptible GPUs for batch work with retries; committed capacity for the baseline.
- Output-token control: maximum tokens, concise instructions, reasoning budgets.
- Speculative decoding for latency-bound, low-concurrency tiers (lesson 4).
The ranking is judgment, not data. Every lever has a quality or complexity cost, and you should state it.
Real-World Application
Before launch, benchmark one replica open-loop on production-shaped traffic and write down the goodput at your target. Plan replicas with the formula, check Little’s law against the cache pool, and choose an autoscaling signal that leads. Measure your actual cold-start time and put it in the plan. Alert on TTFT, ITL and error symptoms; build a cause dashboard from the engine’s metrics; write a runbook for each failure above, and rehearse a canary rollback.
Interview Perspective
Expect: “Capacity-plan 25 requests per second at 800 input and 200 output tokens”, “What do you autoscale on and why not GPU utilization?”, “Traffic doubles every Monday at 9 and users complain for ten minutes”, “Cost doubled after a prompt change but traffic is flat, what do you check first?”. A strong answer gives the formula, one worked number, the cold-start effect and the cache cross-check.
Common mistakes: autoscaling on CPU or GPU utilization; round-robin routing; benchmarking with identical prompts in a closed loop; a health check that returns 200 while the GPU is wedged; ignoring cold start in the scaling plan; sizing from average rather than peak.
Provenance: Common industry pattern and Generated practice. These are standard operations topics for ML-infrastructure and system-design rounds; none is verified for a named company.
Practice Questions
- Basic: Which metrics do you export from an LLM serving replica, and which do you page on?
- Intermediate: Capacity-plan 25 requests per second at peak, 800 input and 200 output tokens, if one replica sustains 1,800 output tokens per second at target.
- Advanced: After a feature prepends the user’s name to the system prompt, TTFT and cost rise. Explain why and fix it.
- Product-Company: Roll out a quantized model to all traffic safely.
Activity
Take a service you know or invent one with traffic numbers. Compute replicas with a margin and a spare, cross-check with Little’s law against a KV pool you choose, and estimate cold-start time from image size, weight size and load rate. Then say which signal you would scale on and how far ahead of a known ramp you would start.
Homework
Write a one-page operations plan: SLOs per traffic class, the paging alerts and the cause dashboard, the capacity calculation, the autoscaling signal and cold-start mitigations, routing policy, a benchmark design with its pitfalls controlled, and a runbook entry for the three failures you rank most likely.
Quick Revision
- Plan , plus spares. Cross-check with Little’s law and the KV pool.
- Scale on queue depth, KV utilization or TTFT, not CPU or GPU utilization. Scale up fast, down slowly, with a drain.
- Cold start is image, weights, graph capture and warm-up; plan for it or scale ahead of ramps.
- Route to the least loaded or the replica with the prefix; retry only safe, pre-first-token failures; hedging doubles load.
- Benchmark open loop, realistic lengths, percentiles, warm, with cache control; report goodput at the target.
- Page on symptoms, dashboard the causes. Health checks should generate a token.
- Degrade on purpose with clear 429 or 503 responses.
Check yourself
- Walk-through: Traffic doubles every Monday at 9 a.m. and users complain about slow starts for ten minutes. Diagnose and fix.
- Variation: Cost doubled after a prompt change but traffic is flat. What do you check first?
- Common misconception: “GPU utilization at 95 percent means we are serving efficiently.” It can mean saturation or preemption.
Related
Resources & Further Reading
Checked sources to go deeper. The essential ones come first in each group.
Official documentation
Metrics (NVIDIA NIM Benchmarking for LLMs) (opens in a new tab)
A second vendor's definitions of TTFT, inter-token latency and throughput for comparing benchmark reports.
Further reading
Chapter 5: Alerting on SLOs (opens in a new tab)
Turns a latency or error objective into alert rules, which is the step after choosing which symptoms to page on.
More for this module: Inference engineering resources
Practice
Test what you just read. Quizzes and cards are grouped by module: Inference engineering.
Check yourself16 questions on what this lesson set out to teach
Checking answers needs JavaScript. You can still read every question and option below.
Keyboard: arrow keys move between options. Space or Enter selects the focused option.