FullStack AI Hub
Studio
Reference architecture

Model Serving Capacity Planning

Quantitative capacity planning method sizing GPU pools from token histograms, KV-cache memory equations, Little's Law queueing bounds, autoscaling, and N+1 reserves.

18 minVerified 2026-11-254 primary sources
Model Serving Capacity Planning
On This Page

Architecture

Model serving capacity planning sizes GPU VRAM pools, continuous batching admission limits, autoscaling metrics, and N + 1 failover redundancy quantitatively from empirical prompt and decode token distributions rather than naive request counts—keeping peak KV-cache occupancy inside safe HBM limits so tail TTFT and TPOT latency never collapse under concurrency spikes.

Intent and policy
Validated request
Controlled execution
Independent verification
Telemetry and response
Conceptual teaching model synthesized from:Efficient Memory Management for Large Language Model Serving with PagedAttentionvLLM V1 scheduler at v0.10.2Kubernetes resource management for Pods and containersHorizontal Pod Autoscaling

Traditional stateless web backends scale simply on RPS x average handler CPU. LLM serving fails under that rubric along two independent hardware ceilings simultaneously: long-context prefills consume quadratic/dense compute FLOPs driving queuing spikes in Time-to-First-Token (TTFT), while long concurrent generations hold gigabytes of stateful KV-cache blocks in GPU HBM for multiple seconds per request, bounding maximum safe concurrency regardless of CPU idle headroom. Sizing clusters without empirical token CDFs (P50, P95, P99), prefix-sharing hit rates, and warm container boot times leads directly to cascading preemption storms under real bursts.

KV-Cache Block Allocator (Paged vs Contiguous)

Prompt Length (L tokens)64 tokens
Blocks per seq: ⌈L/B⌉ = 4Page Size B = 16
Active Sequences (Concurrency)3 requests
Total blocks needed: 12Pool Capacity: 32
Physical GPU Block Table (32 × 16-Token Pages)Allocated: 12/32 Blocks
#0S0
#1S0
#2S0
#3S0
#4S1
#5S1
#6S1
#7S1
#8S2
#9S2
#10S2
#11S2
#12·
#13·
#14·
#15·
#16·
#17·
#18·
#19·
#20·
#21·
#22·
#23·
#24·
#25·
#26·
#27·
#28·
#29·
#30·
#31·
Blocks per Seq⌈64/16⌉ = 4
Allocated Blocks12 / 32
Internal Waste0 tokens
Fragmentation0%

1. KV-Cache Memory Equations and Queue Concurrency Sizing

Per-token Key-Value cache storage scales with transformer layer count LL, KV head count nkvn_{\text{kv}} (GQA group count rather than query heads!), head dimension dheadd_{\text{head}}, and KV element bytes bkvb_{\text{kv}} (2 for FP16/BF16, 1 for FP8):

BytesKV/token=2⋅L⋅nkv⋅dhead⋅bkv,Cmax⁡=⌊VRAMKV, usableS‾effective⋅BytesKV/token⌋\text{Bytes}_{\text{KV/token}} = 2 \cdot L \cdot n_{\text{kv}} \cdot d_{\text{head}} \cdot b_{\text{kv}}, \quad C_{\max} = \left\lfloor \frac{\text{VRAM}_{\text{KV, usable}}}{\overline{S}_{\text{effective}} \cdot \text{Bytes}_{\text{KV/token}}} \right\rfloor

Where S‾effective=(Sprompt(1−hprefix)+Soutput)\overline{S}_{\text{effective}} = (S_{\text{prompt}}(1 - h_{\text{prefix}}) + S_{\text{output}}) adjusts resident context length for shared prefix hits hprefixh_{\text{prefix}} (Radix / Automatic Prefix Caching). Applying Little's Law, steady-state sustainable arrival rate obeys λmax⁡=CtargetWsojourn\lambda_{\max} = \frac{C_{\text{target}}}{W_{\text{sojourn}}}, where keeping cluster KV block residency at <= 75% ensures queueing buffer against Poisson arrival bursts and long-tail decode streams.

Worked Cluster Sizing Scenario (Llama-3-70B FP8, 4x H100 80GB)

Suppose a cluster serves a 70B FP8 model (~71 GB weights spread across TP=2, i.e., 35.5 GB weights + 4.5 GB activations/overhead = 40 GB non-KV usage per 80 GB H100 -> leaving 80 GB total KV cache headroom per 2x H100 replica):

  • Per-token KV cost (80 layers, GQA 8, d=128, FP16 KV cache): 2×80×8×128×2=327,680 B/tok2 \times 80 \times 8 \times 128 \times 2 = 327,680\text{ B/tok} (320 KB/token, or 160 KB if quantized to FP8 KV).
  • Workload Mix: P95 conversation consumes 4,000 prompt tokens (50% shared prefix cache hit -> 2,000 unshared KV tokens) + 500 generated tokens = 2,500 net KV tokens = 800 MB VRAM per stream (~781 MB rounded to 16-token blocks).
  • Per 2x H100 Replica Safe Concurrency (75% high-watermark): 80 GB×0.750.80 GB=75\frac{80\text{ GB} \times 0.75}{0.80\text{ GB}} = 75 simultaneous streams. At mean 4.5s generation duration, each replica drains λ=754.5≈16.6 req/s\lambda = \frac{75}{4.5} \approx 16.6\text{ req/s} cleanly (N + 1 redundancy adds 1 warm standby replica to absorb single-node failure or rolling container drain without breaching SLA!).
Architecture claim
Representative test
Production signal
Decision gate
Review or rollback
Conceptual teaching model synthesized from:Efficient Memory Management for Large Language Model Serving with PagedAttentionvLLM V1 scheduler at v0.10.2Kubernetes resource management for Pods and containersHorizontal Pod Autoscaling

2. Capacity, Replication, and Autoscaling Decisions

DecisionRequired evidenceReview trigger
Size GPU VRAM pools using P95 effective sequence length + prefix-sharing ratio (<= 75% steady KV fill).Production prompt/output CDF & APC hit telemetryContext window limit raise or RAG top-KK jump
Scale on vllm:num_requests_waiting & gpu_cache_usage_perc rather than Kubernetes CPU utilization.P95 TTFT vs HPA trigger latency traceCold container weight load exceeds SLA (45–180s)
Reserve explicit 20–30% headroom plus N + 1 replica availability for single-AZ/node failure drains.Chaos worker termination drain drill during loadPeak seasonal traffic shift or pool contraction
Favor Data Parallel replica scaling once TP satisfies latency & VRAM fit cleanly (TP=2/4 -> scale replicas).Cross-batch TTFT/TPOT sweep across TP configsQuantization upgrade (BF16 -> FP8) shrinking weight footprint

3. Fleet & Headroom Sizer Implementation in Python

python
import math
from dataclasses import dataclass
​
​
@dataclass(frozen=True)
class WorkloadProfile:
avg_prompt_tokens: int
p95_output_tokens: int
prefix_cache_hit_rate: float
mean_stream_duration_sec: float
target_peak_rps: float
​
​
def size_inference_fleet(
model_weights_gb: float,
gpu_vram_gb: float,
tp_degree: int,
kv_kb_per_token: float,
workload: WorkloadProfile,
safety_kv_watermark: float = 0.75,
) -> dict[str, int | float]:
"""Size replicas, safe max concurrency, and N+1 failover reserve from token distributions."""
per_gpu_weight = model_weights_gb / tp_degree
usable_kv_gb = (gpu_vram_gb - per_gpu_weight - 4.5) * tp_degree # Reserve 4.5GB/GPU workspace
if usable_kv_gb <= 0:
raise ValueError("Model weights + runtime workspace exceed GPU pool VRAM; increase TP")
​
eff_tokens = workload.avg_prompt_tokens * (1.0 - workload.prefix_cache_hit_rate) + workload.p95_output_tokens
stream_kv_gb = (eff_tokens * kv_kb_per_token) / (1024.0 * 1024.0)
​
safe_concurrency = int((usable_kv_gb * safety_kv_watermark) // stream_kv_gb)
replica_rps = safe_concurrency / max(0.5, workload.mean_stream_duration_sec)
active_replicas = math.ceil(workload.target_peak_rps / max(0.1, replica_rps))
​
return {
"gpus_per_replica": tp_degree,
"safe_concurrency_per_replica": safe_concurrency,
"sustainable_rps_per_replica": round(replica_rps, 2),
"active_replicas": active_replicas,
"total_replicas_n_plus_1": active_replicas + 1,
"total_gpus_provisioned": (active_replicas + 1) * tp_degree,
}
​
​
fleet = size_inference_fleet(
model_weights_gb=71.0,
gpu_vram_gb=80.0,
tp_degree=2,
kv_kb_per_token=320.0,
workload=WorkloadProfile(4000, 500, 0.50, 4.5, 45.0),
)
assert fleet["total_replicas_n_plus_1"] >= 4

Decisions

DecisionRequired evidenceReview trigger
Size replicas using P95/P99 context/decode distributions + N+1 AZ headroom rather than averages.KV occupancy histogram & load-test saturation point &lt;= 80%Context limit increase or reasoning traffic shift
Autoscale strictly on vllm:gpu_cache_usage_perc and waiting queue depth instead of host CPU %.Synthetic burst scale-out verifying zero OOM preemptionsEngine version upgrade or HPA webhook tuning

Alternatives and trade-offs

  • Smallest Viable Tensor Parallelism + Data-Parallel Replicas vs. Wide TP=8: Smaller TP groups minimize intra-node all-reduce synchronization overhead and shrink hardware failure blast radius cleanly compared to monolithic 8-way TP instances.

Failure modes

  • Sizing exclusively around uniform short averages: Mean generation length (250 tokens) masks a heavy tail (10% deep reasoning traces emitting 4,000 tokens) that silently monopolizes 65% of total KV blocks under burst concurrency.
  • Counting cold containers in ready autoscaling capacity: Downloading/loading 70 GB–140 GB shards into VRAM takes 60–180s (even off local NVMe caches); traffic spikes collapse queues well before Kubernetes HPA boots cold pods unless warm buffers or pre-cached NVMe DaemonSets are provisioned.
  • Client retry storms multiplying overload: Unbounded gateway retries re-inject timed-out 32k prefill prompts back onto saturated schedulers, guaranteeing preemption livelock unless ingress admission rejects cleanly at HTTP 429 once waiting queues breach SLA deadlines.
  • Over-provisioning TP=8 unnecessarily when TP=2 suffices: Splitting a quantized model across 8 GPUs adds unnecessary NVLink all-reduce synchronization overhead per layer and turns 1 failing GPU into an 8-GPU blast radius rather than isolated smaller DP replicas.

Operational checklist

  • Empirical P50/P95/P99 prompt length, output length, and prefix sharing histograms updated monthly.
  • Ingress admission limits enforce explicit waiting-queue deadlines (HTTP 429) cleanly ahead of GPU OOM preemption.
  • Autoscalers read vllm:gpu_cache_usage_perc and waiting queue depth instead of host CPU %.
  • Scale-down preStop hooks wait for active SSE decode streams to flush cleanly before terminating containers.
  • Cold weight start times (image + model load) measured realistically inside failover capacity models.

Connected Practice

Sources

  • Serving capacity primary references: vllm-paper, vllm-v0102-scheduler, kubernetes-resource-management, kubernetes-hpa
Interactive Simulator

Step through live KV-cache block paging

Inspect virtual-to-physical VRAM page tables, Copy-on-Write forks, and internal fragmentation in the PagedAttention simulator.

Weekly Engineering Dispatch

Subscribe to Engineering Briefings

Join AI systems engineers receiving architecture teardowns, benchmark notes, and new simulator releases. Unsubscribe anytime.