FullStack AI Hub
Studio
lesson depth
Mastery
not started · 0%

Model Serving Capacity Planning

Translate workload distributions and service objectives into accelerator, memory, queue, and redundancy capacity.

Freshness: current•15 min read•Production Infrastructure and AI Economics

Key Learning Outcomes

  • ✓Explain the operating model behind Model Serving Capacity Planning.
  • ✓Evaluate trade-offs and failure modes for Model Serving Capacity Planning.
  • ✓Apply Model Serving Capacity Planning to a production decision.
Full Technical Reference Document

Mental model

LLM capacity planning cannot rely on classic stateless web RPS math because generative inference latency and memory cost depend violently on token-length distributions, not flat request counts. Because every concurrent request locks multi-megabyte KV-cache HBM blocks linearly across its full input + output token sequence while compute latency splits between heavy parallel prefill (TTFT) and memory-bandwidth-bound sequential decode (TPOT), reliable sizing starts from P50/P95/P99 prompt & generation token distributions, prefix-cache reuse ratios, quantization precisions, cold-start model weight loading lag, and strict VRAM headroom (25%–30%) + N + 1 failover redundancy—verified empirically cleanly via production trace replay rather than synthetic uniform prompts!

Measure P50/P95 Input & Output Tokens
Budget Weights + Activation + 30% KV Reserve
Profile TTFT/TPOT Goodput Curve on Trace Replay
Add Cold-Start Lag & Autoscaler Buffer
Validate N+1 Pod/AZ Failure Without Preemptions
Conceptual teaching model synthesized from:vllm-paper,kubernetes-resource-management

Learning outcomes

  • Compute explicit HBM VRAM budgets partitioning static model weights (FP16/FP8/AWQ), CUDA activation workspaces, and dynamic PagedAttention KV-cache capacity (free KV blocks).
  • Explain why token-length tails (P95 long-context documents) and output-to-input ratios distort naïve requests-per-second averages dramatically.
  • Factor container image pulls and multi-gigabyte weight deserialization cold-starts (30–240 s) cleanly into warm baseline replica floors and HPA buffers.
  • Size N + 1 redundancy and isolated prefill/decode pools so node preemption or AZ failure never triggers cluster-wide queue collapse.

Theory

Suppose a 70B dense parameter model (GQA 8 KV heads, FP8 weights ~70 GB) deploys across 2x H100 80 GB (160 GB total HBM): after ~140 GB is occupied immediately by model weights (70 GB/GPU? Wait: 70 GB total split across 2 GPUs = 35 GB/GPU -> leaving 45 GB/GPU / 90 GB aggregate for activations, CUDA graphs, and KV blocks! Checking exact arithmetic keeps numbers cleanly grounded!). Using KV bytes/token = 2 * layers * kv_heads * head_dim * bytes_per_val: at 80 layers, 8 KV heads, 128 head_dim, FP8 (1 byte) or BF16 (2 bytes), one 32K-token context locks 2 * 80 * 8 * 128 * 2 = 327,680 bytes/token * 32,768 = ~10.7 GB of HBM strictly for ONE user's KV cache! A handful of unexpected 64K inputs therefore exhausts KV pools abruptly if provisioned only around "mean 1,200-token" averages!

Capacity Input VariablePhysical GPU Bottleneck DrivenProduction Sizing & Safety Rule
Static Weights + CUDA Graphs (W)Baseline HBM committed before request 1Always measure real vLLM engine startup memory (gpu_memory_utilization=0.90), leaving OS/NCCL room
P95 Sequence Length ×\times Peak Active ConcurrencyDynamic KV-Cache block pool exhaustion (num_preemptions)Keep 25%–30% free KV-block margin at predicted daytime peak so long answers never evict live neighbors!
Input Prefill vs. Output Decode RatioPrefill saturates Tensor Cores (TTFT); Decode saturates HBM bandwidth (TPOT)Large RAG (8K in / 150 out) behaves compute-bound, requiring prefill-decode disaggregation or chunked prefill cleanly earlier than chat (300 in / 800 out)!
Weight Load & Pod Warmup Time (T_boot)Horizontal autoscaler reaction lag (45–180 s)Hold warm baseline replicas sized to absorb T_boot burst derivative cleanly without waiting for cold nodes

Trace Replay Under N + 1 Failure and Queue-Collapse Cliffs

Always validate candidate fleet sizes on trace replay (real production timestamped prompt/output histograms) under missing-node failure (N healthy replicas -> simulate losing 1 replica cleanly during peak burst!). At 95% utilization, losing 1 of 10 pods spikes the remaining 9 past 105% demand—turning graceful 20 ms queues immediately into catastrophic 30-second timeout cascades where waiting queues pile up and every retried client compounds load 3x (Metastable Queue Collapse)! Keeping steady-state utilization cleanly under 65%–70% alongside upstream admission shedding (HTTP 429/503) guarantees remaining healthy GPUs drain cleanly through failovers.

python
from dataclasses import dataclass
​
@dataclass(frozen=True)
class FleetSizingInput:
peak_tokens_per_sec_decode: float
single_replica_goodput_tps: float
single_replica_kv_gb: float
kv_gb_per_p95_req: float
p95_concurrent_reqs: int
target_utilization: float = 0.70
​
def compute_n_plus_1_replicas(cfg: FleetSizingInput) -> dict[str, int]:
"""Size GPU replica fleet covering compute goodput, KV block capacity, and 1 failed worker."""
compute_replicas = max(1, int(-(-(cfg.peak_tokens_per_sec_decode / (cfg.single_replica_goodput_tps * cfg.target_utilization)) // 1)))
total_kv_needed_gb = cfg.p95_concurrent_reqs * cfg.kv_gb_per_p95_req
usable_kv_per_replica = cfg.single_replica_kv_gb * 0.75 # Preserve 25% KV headroom against preemptions
kv_replicas = max(1, int(-(-(total_kv_needed_gb / usable_kv_per_replica) // 1)))
​
active_floor = max(compute_replicas, kv_replicas)
return {
"active_replicas": active_floor,
"recommended_with_n_plus_1": active_floor + 1,
}

Alternatives and trade-offs

  • Warm-Baseline + Trace-Verified N + 1 Dedicated GPU Fleet + Spillover Burst API: Guarantees deterministic TTFT/TPOT SLAs, protects private KV caches cleanly, and prevents cold-boot drops during sudden traffic ramps via instant overflow onto serverless pay-per-token APIs during extreme 3x launches—balancing fixed reserved GPU costs cleanly against un-provisioned launch surges!
  • Pure Aggressive Scale-to-Zero GPU Autoscaling: Minimizes overnight idle cloud spend on low-volume internal batch jobs, while imposing severe 1–4 minute cold-start SLA breaks whenever daytime interactive users hit zero warm pods.
  • Disaggregated Prefill / Decode Fleets: Splits heavy long-context prefill workers cleanly onto high-FLOP compute pods while keeping decode replicas focused on smooth TPOT streams—unmatched at massive cluster scale, yet premature overhead below tens of GPUs.

Failure modes and misconceptions

  1. Sizing Capacity From Mean RPS Ignoring Token-Length Tails: Provisioning for 50 req/s averaging 500 tokens crashes instantaneously the afternoon enterprise RAG users paste 24,000-token PDFs cleanly driving 30x KV consumption and 15x prefill FLOPs per request!
  2. Ignoring Container Weight Download & Engine Warmup Lag (30–240 s): Configuring tight Kubernetes HPA scale-ups at 85% load guarantees 4-minute outage waves while giant 70 GB Safetensors checkpoints stream down over container registries and compile CUDA graphs! Keep cached NVMe weights (hostPath/DaemonSet pre-warmed images) and conservative scale-up triggers (55%–65%).
  3. Provisioning 100% VRAM Without KV Eviction Headroom (gpu_memory_utilization): Packing active queues right to 99% of KV blocks sets off constant recomputation/swap preemption storms under minor output-length variance.
  4. Zero N + 1 Redundancy Margin During Peak (Metastable Collapse): Running 3 replicas at 92% capacity triggers total SLA collapse the instant 1 spot node or GPU driver resets (Xid fault), pushing load to 138% across survivors cleanly.
Reflect before revealing the guide

Decision scenario

Your SaaS copilot handles steady daytime enterprise coding and RAG summarization (P50 = 1,500 input / 300 output tokens, P95 = 18,000 input / 1,100 output tokens) alongside sharp Monday morning launch spikes, running on multi-GPU Kubernetes nodes taking 90 s to warm new serving pods. Measure real trace replay goodput under exact FP8 weights + GQA KV footprints, allocate 30% free KV margin, maintain warm baseline capacity holding <= 65% target daytime utilization plus N + 1 failover redundancy cleanly verified against simulated replica kills, pre-cache weights locally on node NVMe volumes to trim autoscaling lag, and wire upstream admission queues to shed overload or route brief extreme spikes cleanly to an overflow endpoint.

Trade-offs

Token-distribution-driven N + 1 capacity planning prevents catastrophic preemption thrashing, cold-start blackouts, and metastable failover collapses across production GPU inference fleets, while requiring intentional investment in warm baseline reserve nodes rather than squeezing 95%+ naive hardware utilization.

Prerequisites & Related Concepts (4)

Private notes

0 words
Included In Free Course
Free · Verifiable Credential

FS-201Production LLM Engineer

Design an observable full-stack LLM product from capability validation through interfaces retrieval evaluation security and operations.

37 concepts~35h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.

Next