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

Inference Autoscaling and Backpressure

Scale from demand and saturation signals while bounding queues, retries, and cold-start instability.

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

Key Learning Outcomes

  • ✓Explain the operating model behind Inference Autoscaling and Backpressure.
  • ✓Evaluate trade-offs and failure modes for Inference Autoscaling and Backpressure.
  • ✓Apply Inference Autoscaling and Backpressure to a production decision.
Full Technical Reference Document

Mental model

Autoscaling adds GPU replicas over minutes while multi-gigabyte model weights load into VRAM, whereas backpressure protects active replicas within milliseconds. Bounding admitted concurrency via Little's Law, autoscaling on KV-block utilization and waiting queues rather than CPU, and shedding excess load via AIMD prevents cascading timeout and retry collapse.

Request deadline check
AIMD concurrency gate
vLLM scheduler KV queue
HPA KV-block scale signal
Graceful pod drain
Conceptual teaching model synthesized from:Horizontal Pod AutoscalingSite Reliability EngineeringKubernetes resource management for Pods and containersvLLM V1 scheduler at v0.10.2

Learning outcomes

  • Apply Little's Law (L=λWL = \lambda W) to distinguish queueing delay from prefill and decode execution latency in LLM serving.
  • Replace broken CPU utilization autoscaling triggers with KV-cache block utilization, waiting queue depth, and preemption metrics.
  • Bridge multi-minute GPU container cold starts using AIMD concurrency limits, retry budgets, and jittered HTTP 429 shedding.
  • Propagate request deadlines and configure Kubernetes readiness gates plus graceful pod termination drains to avoid orphaned decode streams.

Theory

Horizontal Pod Autoscaling (HPA) in stateless microservices reacts within seconds because containers start rapidly and CPU utilization tracks saturation. LLM serving violates both assumptions. Loading a 70B BF16 model across tensor-parallel GPUs takes two to six minutes for image pull, weight deserialization, NCCL setup, and CUDA graph capture. Meanwhile, host CPU utilization frequently stays under 25% even when GPU HBM bandwidth or KV-cache blocks reach 99% exhaustion.

Saturation starts with Little's Law, linking average active requests LL, arrival rate λ\lambda, and mean residence time WW:

L=λWL = \lambda W

For autoregressive generation, total latency WW decomposes into scheduler wait time WqueueW_{\text{queue}}, compute-bound prefill duration TprefillT_{\text{prefill}} (determining Time To First Token, TTFT=Wqueue+Tprefill\text{TTFT} = W_{\text{queue}} + T_{\text{prefill}}), and bandwidth-bound decode steps over NoutN_{\text{out}} output tokens at Inter-Token Latency (ITL\text{ITL} or TPOT\text{TPOT}):

W=Wqueue+Tprefill+Nout⋅TPOTW = W_{\text{queue}} + T_{\text{prefill}} + N_{\text{out}} \cdot \text{TPOT}

When arrival rate λ\lambda exceeds completion rate μ\mu, active concurrency LL climbs until physical KV blocks fill. In vLLM V1 (vllm/v1/core/sched/scheduler.py), exhausting free KV blocks forces sequence preemption—evicting or recomputing running requests—spiking TTFT and TPOT across co-scheduled streams. Unbounded queues inflate WqueueW_{\text{queue}} until clients time out, fire retries, and multiply λ\lambda against a saturated cluster.

To preserve latency inside SLOs while Kubernetes HPA provisions replicas, gateways enforce Additive Increase, Multiplicative Decrease (AIMD) concurrency control (following Google SRE overload patterns):

ct+1={min⁡(cmax⁡,ct+α),if TTFTp95≤SLO and uKV<0.85max⁡(cmin⁡,⌊ct⋅β⌋),otherwise, with β∈(0.5,0.85)c_{t+1} = \begin{cases} \min(c_{\max}, c_t + \alpha), & \text{if } \text{TTFT}_{p95} \le \text{SLO} \text{ and } u_{\text{KV}} \lt 0.85 \\ \max(c_{\min}, \lfloor c_t \cdot \beta \rfloor), & \text{otherwise, with } \beta \in (0.5, 0.85) \end{cases}

Excess traffic past ctc_t receives HTTP 429 with jittered Retry-After headers and strict client retry budgets (e.g., capping retries at 10% of volume). Simultaneously, HPA scales on engine custom metrics—KV-block saturation (kv_cache_usage_perc), waiting queue depth, and num_preemptions_total—paired with slow scale-down stabilization (5–10 minutes) and terminationGracePeriodSeconds long enough to drain active SSE streams before SIGKILL.

Worked quantitative example

Consider one GPU replica sustaining μ=8 req/s\mu = 8\text{ req/s} at mean duration W=2.5 sW = 2.5\text{ s}. By Little's Law, steady concurrency is L=8×2.5=20L = 8 \times 2.5 = 20 active sequences at 85% KV-block usage. Suppose traffic triples to λ=24 req/s\lambda = 24\text{ req/s} for 180 s while new pods need 210 s to warm weights.

With an unbounded queue, backlog grows at λ−μ=16 req/s\lambda - \mu = 16\text{ req/s}, accumulating 2,880 queued requests in 180 s. The tail request waits Wqueue=2,880/8=360 sW_{\text{queue}} = 2{,}880 / 8 = 360\text{ s}—far past a 15 s client timeout—causing retries that drive effective λ\lambda above 40 req/s while replicas burn cycles decoding abandoned sockets.

With AIMD backpressure (c_min = 8, c_max = 32, alpha = 1, beta = 0.7), once KV usage hits 90% and TTFT passes 900 ms, AIMD cuts concurrency from 28 to 19 (floor(28 * 0.7)). Admitted requests hold &lt; 900 ms TTFT and smooth ITL, while excess 16 req/s fail fast in &lt; 2 ms with 429 + jitter until newly scaled GPU pods pass readiness probes at 210 s.

Autoscaling and backpressure signal comparison

Signal / MechanismReaction HorizonFailure Mode When Used AloneProduction Role
Host CPU Utilization30–60 sBlind to GPU VRAM and KV pressureNever use as primary LLM HPA metric
Raw GPU SM Utilization15–30 sReads high in prefill, lower in decodeDiagnostic telemetry only
KV-Cache Utilization + Waiting Queue15–60 sToo slow for sudden 3x traffic spikesPrimary HPA custom scale-out trigger
AIMD Concurrency Gate + Bounded Queue&lt; 5 msSheds demand rather than adding capacityImmediate shield during cold starts

Trade-offs

Aggressive scale-up policies with short stabilization windows protect headroom during sustained demand ramps, yet brief spikes trigger expensive multi-minute model loads and scale-down churn if cooldown windows stay tight. Keeping warm standby replicas absorbs bursts smoothly at the cost of persistent idle GPU spend.

Tight concurrency caps and sharp multiplicative backoff (beta = 0.5) protect interactive P99 TTFT rigorously, though they reject borderline bursts slightly earlier than larger queues. Partitioning priority tiers—shedding offline batch summarization jobs before interactive chat streams—protects user-facing SLOs without over-provisioning for peak batch arrivals.

Failure modes and misconceptions

  • Scaling GPU replicas on Kubernetes CPU utilization. Decode throughput bottlenecks on HBM bandwidth and KV blocks, leaving CPU cores largely idle while TTFT degrades into tens of seconds.
  • Allowing unbounded ingress queues ahead of vLLM. Queuing requests past client timeouts converts overload into universal collapse: every request times out, retries fire simultaneously, and zero callers finish.
  • Dropping client streams without propagating cancellation. If an ingress proxy disconnects without forwarding AbortSignal or gRPC deadline cancellation, GPUs keep decoding wasted tokens and pinning KV blocks.
  • Counting unready pods or lacking scale-down drains. Readiness probes must gate traffic until weight loading and CUDA graphs finish, while preStop drains and terminationGracePeriodSeconds preserve live SSE streams during scale-in.
  • Synchronized client retries without jitter. Immediate retries on 503 or 429 create self-inflicted thundering herds that block AIMD recovery.

Decision scenario

An interactive chat service runs on 4 GPU pods sustaining 32 req/s combined (8 req/s each) at 82% KV saturation. At 09:00 UTC, arrival rate jumps to 96 req/s in 30 seconds while new GPU replicas need 4 minutes to load weights.

Configure deadline propagation (request_timeout = 12s), priority admission shedding batch workloads first, and an AIMD concurrency limiter triggered by KV utilization (&gt; 0.85) and TTFT P95 (&gt; 850ms) returning HTTP 429 with jittered Retry-After. Drive Kubernetes HPA from kv_cache_usage_perc > 0.70 and num_requests_waiting, keep scaleDown stabilization at 600s, gate readiness on initialized CUDA graphs, and add a preStop drain hook.

Implementation example

This Python AIMD concurrency controller and deadline-aware admission gate shrinks active concurrency multiplicatively when KV saturation or TTFT breaches SLO bounds and sheds stale or excess requests immediately.

python
from dataclasses import dataclass
import math
import time
​
@dataclass
class ReplicaHealth:
kv_cache_ratio: float
ttft_p95_ms: float
waiting_requests: int
​
class AimdInferenceGate:
def __init__(self, initial: int = 24, c_min: int = 4, c_max: int = 48) -> None:
self.limit, self.c_min, self.c_max, self.in_flight = float(initial), c_min, c_max, 0
​
def update_window(self, h: ReplicaHealth) -> int:
overloaded = h.kv_cache_ratio >= 0.85 or h.ttft_p95_ms > 900.0 or h.waiting_requests > 16
if overloaded:
self.limit = max(float(self.c_min), math.floor(self.limit * 0.7))
else:
self.limit = min(float(self.c_max), self.limit + 1.0)
return int(self.limit)
​
def try_admit(self, deadline_epoch_s: float, min_budget_s: float = 0.5) -> tuple[bool, str]:
if deadline_epoch_s - time.time() < min_budget_s:
return False, "429_deadline_exhausted"
if self.in_flight >= int(self.limit):
return False, "429_aimd_concurrency_shed"
self.in_flight += 1
return True, "admitted"
​
gate = AimdInferenceGate(initial=24)
assert gate.update_window(ReplicaHealth(0.91, 1120.0, 19)) == 16
assert gate.try_admit(time.time() + 10.0) == (True, "admitted")
Reflect before revealing the guide

Why does scaling LLM replicas on CPU utilization fail during bursts, and how do AIMD concurrency limits bridge multi-minute cold starts?

Prerequisites & Related Concepts (3)

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.