Production operations: capacity, scaling and failure

  • Production
  • 45 min
  • Lesson 6 of 7 in Inference engineering
  • Last verified

Open slides(32 slides)

Before you start

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.

Diagram: Requests pass a gateway and a router into replica pools, with an external API as overflow.

overflow and failover

Clients

Gateway: authentication, quotas, rate limits

Router: model choice, prefix affinity, least loaded, adapter aware

Replica pool A: engine and GPUs

Replica pool B: other model or tier

External API fallback

Metrics, traces, logs

Autoscaler

Weights in object storage plus node cache

Diagram summary: Requests pass a gateway and a router into replica pools, with an external API as overflow. Replicas emit metrics that drive an autoscaler. Weights load from object storage with a local cache on each node.

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

  1. Characterize traffic: peak and daily shape of requests per second, input and output token distributions at p50 and p95, how much prefix is shared.
  2. 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.
  3. replicas=peak loadper-replica capacity×target utilization\text{replicas} = \dfrac{\text{peak load}}{\text{per-replica capacity} \times \text{target utilization}}, 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).
  4. Cross-check with Little’s law and the cache: concurrency in flight=arrival rate×latency\text{concurrency in flight} = \text{arrival rate} \times \text{latency}, 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: 30×250=7,50030 \times 250 = 7{,}500 tokens per second. A replica (a 70B model on four GPUs) is benchmarked at 2,000 output tokens per second at the target latency.

  • 7,500÷2,000=3.757{,}500 \div 2{,}000 = 3.75 replicas of raw capacity.
  • At 0.65 target utilization: 3.75÷0.65=5.83.75 \div 0.65 = 5.8, 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 30×8≈24030 \times 8 \approx 240 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.
StepCalculationResult
Peak output rate30×25030 \times 2507,500 tokens/s
Raw replicas7,500÷2,0007{,}500 \div 2{,}0003.75
At 0.65 utilization3.75÷0.653.75 \div 0.655.8, so 6
Plus one spare6+16 + 17 replicas, 28 GPUs
Sequences in flight30×8 s30 \times 8\ \text{s}about 240
Per serving replica240÷6240 \div 6about 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.

Diagram: A new replica is not useful until it has pulled its image, loaded its weights, captured CUDA graphs and warmed up.

Scale-up signal

Pull container image

Load weights
140 GB at 2 GB/s = 70 s

Capture CUDA graphs

Warm up

Ready: takes traffic

Diagram summary: A new replica is not useful until it has pulled its image, loaded its weights, captured CUDA graphs and warmed up. That can take minutes, which is why you scale on signals that lead, such as queue depth, not on signals that show up after users already wait.

Worked example: traffic doubles at 9 a.m. from 30 to 60 requests per second. Each replica serves 2,000÷250=82{,}000 \div 250 = 8 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, 12×180=2,16012 \times 180 = 2{,}160 requests queue, and the last one waits 2,160÷48=452{,}160 \div 48 = 45 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.
Diagram: A prefix-aware router sends requests that share a prefix to the replica that already holds its cache blocks, so prefill is skipped.

same prefix, same replica

random spread would miss the cache

balanced against hot spots

Request with a shared system prompt

Router hashes the prefix

Replica A: prefix blocks cached

Replica B: cold for this prefix

Fall back to a less loaded replica

Diagram summary: A prefix-aware router sends requests that share a prefix to the replica that already holds its cache blocks, so prefill is skipped. A random spread would miss the cache, and the router must still avoid overloading one replica.

Benchmarking without fooling yourself

MistakeBetter practice
Fixed prompt and output lengthsSample realistic distributions from production traces, including the long tail
Closed loop with N clientsOpen loop: arrivals at a set rate (a Poisson process), so queues, saturation and tails show up
Reporting only averages or peak throughputReport TTFT, ITL and end-to-end latency at p50, p95 and p99, and goodput at the target, across several load levels
No warm-upDiscard warm-up; measure steady state; test cold start separately
A hot prefix cache by accidentControl hit rate explicitly and measure with and without
Comparing engines at different precisionsHold 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.

Diagram: A closed-loop test lets the load fall whenever the server slows, so it hides saturation.

Open loop: 10 requests per second

Arrivals keep coming on schedule

Capacity is 8 req/s

Queue grows, tail latency explodes

Closed loop: 64 clients

Each client waits for its reply

Server slows

Offered load falls automatically

Reports 8 req/s, stable latency

Diagram summary: A closed-loop test lets the load fall whenever the server slows, so it hides saturation. An open-loop test keeps arrivals on schedule, so a server whose capacity is below the arrival rate visibly builds a queue and shows its real tail latency.

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”

Diagram: First ask what changed, then split by symptom.

TTFT up

ITL up

Both, under load

Latency regression

What changed: traffic mix, deploy, model, flags?

TTFT or ITL?

Queue time? KV full or preemptions? Longer prompts? Prefix hit rate dropped? Router imbalance? Cold replicas?

Batch size or context longer? Big prefills interfering? Throttling or noisy neighbour? Interconnect degraded?

Saturation: add capacity, shed load, cap tokens, fix the scaling signal

Fix, then verify against the SLO dashboard

Diagram summary: First ask what changed, then split by symptom. A higher TTFT points to queueing, cache pressure, longer prompts, a lower prefix hit rate, routing or cold replicas. A higher ITL points to batch or context growth, prefill interference, throttling or the interconnect. Both together under load mean saturation. Every branch ends in a fix verified against the SLO dashboard.

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

FailureSymptomMitigation
Out of GPU memorycrashes on long promptscap input and output length, leave memory headroom, quantize the cache, admission control
Preemption stormhigh utilization, falling goodputcap concurrency, add replicas, shorten context
GPU fault or hung kernelstuck requests, an unhealthy nodehealth check that generates a token, not just returns HTTP 200; cordon and replace
Tensor-parallel peer failurethe whole replica group stallswatchdog timeouts, restart the group
Slow or dropped clientszombie sequencescancel on disconnect, per-request timeouts
Thundering herd after a deploycold caches, long queuesgradual rollout, warm pools, rate-limited retries
Bad rolloutsilent quality or speed regressioncanary and shadow traffic, an evaluation gate, automatic rollback
One tenant hogging capacityothers starveper-tenant quotas, fair scheduling, separate pools
Region or provider outageerrorsmulti-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

  1. Raise utilization: right-size replicas, batch better, consolidate pools, move batch work to off-peak.
  2. Prefix caching and prompt design: static prefix first, trimmed context.
  3. Quantization validated by evaluation (lesson 3).
  4. A right-sized model: route easy traffic to a smaller one.
  5. Spot or preemptible GPUs for batch work with retries; committed capacity for the baseline.
  6. Output-token control: maximum tokens, concise instructions, reasoning budgets.
  7. 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 replicas=peak÷per-replica goodput capacity÷target utilization\text{replicas} = \text{peak} \div \text{per-replica goodput capacity} \div \text{target utilization}, 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.

Resources & Further Reading

Checked sources to go deeper. The essential ones come first in each group.

Official documentation

Further reading

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.

0 of 16 answered

Keyboard: arrow keys move between options. Space or Enter selects the focused option.

ObjectivePlan 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.

  1. Question 1 of 16Peak traffic is 20 requests per second at 150 output tokens each. One replica is benchmarked at 900 output tokens per second at the latency target. With 0.7 target utilization and one spare, how many replicas?

    Choose one answer.

  2. Question 2 of 16Arrival is 20 requests per second and a request holds its slot for 9 seconds from admission to last token. Five replicas serve it, and each replica's KV pool holds 30 sequences of the typical size. What does Little's law say?

    Choose one answer.

ObjectiveChoose autoscaling signals that lead rather than lag, account for cold start, and explain why you scale up fast and down slowly with a drain.

  1. Question 3 of 16Which are autoscaling signals that lead rather than lag for an LLM service? Select all that apply.

    Choose all that apply.

  2. Question 4 of 16A replica shows 95 percent GPU utilization, yet goodput is falling. Why can utilization mislead?

    Choose one answer.

  3. Question 5 of 16A new replica pulls its container image in 40 s, loads 70 GB of weights at an assumed 2 GB/s, and then needs 20 s for graph capture and warm-up. How long until it can serve?

    Choose one answer.

  4. Question 6 of 16Every Monday at 9 a.m. traffic doubles, new replicas need four minutes to start, and users see slow starts for about ten minutes. What is the best fix?

    Choose one answer.

  5. Question 7 of 16What should happen before a replica is terminated during scale-in?

    Choose one answer.

ObjectiveChoose a routing policy (least-loaded, prefix-aware, adapter-aware, priority tiers) and say which retries are safe and what hedging costs.

  1. Question 8 of 16Request costs on a service vary by about 100 times between short and long ones. Which routing policy fits best?

    Choose one answer.

  2. Question 9 of 16Which are sound practices for retries and hedging? Select all that apply.

    Choose all that apply.

ObjectiveDesign a benchmark that reports goodput at the target on realistic traffic, and explain why closed-loop load and a hot cache mislead.

  1. Question 10 of 16A closed-loop test with 64 clients reports 8 requests per second and a steady latency. The service's true capacity is 8 requests per second. What does the test fail to show?

    Choose one answer.

  2. Question 11 of 16Three identical benchmark runs against one running server show rising throughput each time. What is the likely cause, and the fix?

    Choose one answer.

  3. Question 12 of 16Which belong in a trustworthy benchmark report? Select all that apply.

    Choose all that apply.

ObjectiveWork through a latency regression by symptom, alert on symptoms while dashboarding causes, and describe graceful degradation for the main failure modes.

  1. Question 13 of 16After a deploy, TTFT and cost rise while ITL is unchanged, and the prefix-cache hit rate has dropped. What is the most likely cause?

    Choose one answer.

  2. Question 14 of 16Inter-token latency rose while TTFT stayed flat. Which cause fits best?

    Choose one answer.

  3. Question 15 of 16Which of these should page an on-call engineer first?

    Choose one answer.

  4. Question 16 of 16A replica passes its HTTP health check while its GPU is hung and every request on it stalls. What is the fix?

    Choose one answer.

Build with this