Phase 05/Operating a distributed serving fleet/Fault tolerance, load balancing, autoscaling
PHASE 05 · Operating a distributed serving fleet

Fault tolerance, load balancing, autoscaling

0%
8 h5 subtopics2 lessons · 2 required
In plain English

A single serving replica is a single point of failure, and a fixed number of replicas is either wasteful at night or overloaded at noon. Running a fleet means answering three questions. What happens when a GPU or a whole node dies mid-sentence (fault tolerance)? How do incoming requests get spread so no replica drowns while another idles (load balancing)? And how does the fleet grow and shrink with demand without thrashing (autoscaling)? Think of a supermarket. Checkouts occasionally break, so a manager reroutes the queue; a greeter points shoppers to the shortest line; and the store opens more tills when queues get long and closes them when they empty. The hard part with LLMs is that a request is not a quick scan, it is a long conversation whose cost depends on prompt length and whose state (the KV cache) is stuck on one machine.

Why it matters

Inference fleets are judged on tail latency and cost per token. Naive round-robin, scaling on CPU utilisation, or restarting a TP group on every hiccup can each double your bill or your p99. This topic gives you the metrics and mechanisms that production teams actually use.

Hiring signal

Skills this topic builds, with the number of the 46 analysed job postings that ask for each. Companies asking: Anthropic, Baseten, Cerebras, Cohere, CoreWeave, Crusoe, Cursor, Databricks, ElevenLabs, Fireworks, Modal, nvidia, OpenAI, Perplexity, Poolside, Thinking Machines, Together AI, xAI.See all skills →

Learning objectives

  • Model request routing policies (round-robin, least-outstanding, prefix-aware) and compare their p50/p99 under skewed prompt lengths.
  • Explain failure modes specific to TP and PP groups and how engines detect NCCL hangs and restart.
  • Choose autoscaling signals (queue depth, KV cache utilisation, tokens per second) over CPU or GPU utilisation and explain why.
  • Design health checks, drain, and graceful shutdown for a streaming inference service.

Key concepts

Least-outstanding-requests routing
Send each request to the replica with the fewest in-flight requests; a cheap proxy for load that beats round-robin for variable-length work.
Prefix-aware routing
Routing requests sharing a prompt prefix to the same replica to reuse cached KV blocks.
Gang failure
In a TP or PP group one rank failing stalls all others; the whole group must be restarted together.
NCCL watchdog timeout
The mechanism that turns a hung collective into an error after a configurable period so a group can be restarted.
Readiness versus liveness probe
Readiness gates traffic (model loaded, warm); liveness restarts a stuck process.
Scale-to-queue
Autoscaling on pending requests or KV cache utilisation rather than CPU/GPU percent, which saturate early and lie.
Graceful drain
Stop accepting new requests, let in-flight streams finish, then exit; avoids cutting responses mid-token.
Cold start
Time to pull the image, load tens of GB of weights, and warm CUDA graphs; the main constraint on how fast autoscaling can react.

Subtopics

  1. 1. Failure modes of distributed inference

    GPU Xid errors, ECC faults, NCCL hangs, OOM from KV growth, node preemption; how a single rank failure propagates through a TP group.

  2. 2. Detection and recovery

    Watchdog timeouts, health endpoints, Kubernetes probes and restart policies, request retries and idempotency for streaming.

  3. 3. Load balancing for LLM traffic

    Why requests are heterogeneous; round-robin versus least-outstanding versus prefix-aware; session affinity and its cost.

  4. 4. Autoscaling signals and policies

    Queue depth, KV cache utilisation, tokens per second, SLO-based scaling; HPA with custom metrics and KEDA; cooldowns and cold-start budgets.

  5. 5. Graceful lifecycle

    preStop hooks, connection draining, terminationGracePeriodSeconds sized to the longest generation, rolling updates of TP groups.

Resources

documentation
repo

Hands-on lessons

L1

Simulate LLM load balancing policies

CPU · your Macnotebook120 minrequired

Goal · A discrete-event simulation of N replicas serving requests with heavy-tailed prompt and output lengths, comparing p50 and p99 latency under round-robin, least-outstanding, and prefix-aware routing.

  1. 1Model a replica as a server with continuous batching where step time grows with batch size (for example 20 ms plus 0.5 ms per sequence) and a max batch of 64.
  2. 2Generate 5000 requests with Poisson arrivals, log-normal prompt lengths, and output lengths from 16 to 1024 tokens; tag 40 percent with one of 10 shared prefixes.
  3. 3Implement round-robin, least-outstanding-requests, and prefix-aware (hash prefix to replica, fall back to least-outstanding when overloaded) routers.
  4. 4Give prefix hits a 60 percent shorter prefill time to model KV reuse.
  5. 5Run each policy at 4 replicas and arrival rates at 50, 80, and 95 percent of capacity; record p50 and p99 end-to-end latency and per-replica utilisation variance.
  6. 6Plot p99 versus load for the three policies.
Deliverable
lb_sim.ipynb with the p99-versus-load plot and a summary table.
Check
At 95 percent load round-robin p99 is at least 1.5x the least-outstanding p99; prefix-aware has the lowest mean latency but higher utilisation variance across replicas.
L2

Fault injection and autoscaling on kind

CPU · your Maccli150 minrequired

Goal · A kind cluster running a stub streaming server that exposes vLLM-style metrics, with readiness and liveness probes, graceful drain, and an HPA that scales on a custom queue-depth metric; you kill pods and verify no in-flight stream is cut.

  1. 1Write stub_server.py (FastAPI) that streams fake tokens for a random 2-20 s per request, exposes /health and /metrics with num_requests_waiting and num_requests_running gauges, and handles SIGTERM by draining in-flight streams before exiting.
  2. 2Containerise it and deploy to kind with readinessProbe on /health, livenessProbe, a preStop sleep, and terminationGracePeriodSeconds 30.
  3. 3Install Prometheus and prometheus-adapter (or KEDA) and expose num_requests_waiting as a custom metric.
  4. 4Create an HPA targeting an average of 2 waiting requests per pod, min 1, max 4, with a 60 s scale-down stabilisation window.
  5. 5Run a load generator with 20 concurrent streams; watch kubectl get hpa until replicas reach 4; stop load and watch scale-down.
  6. 6While 10 streams are active run kubectl delete pod on one replica and record how many streams were cut versus completed.
  7. 7Repeat the deletion without the SIGTERM handler and compare the cut count.
Deliverable
stub_server.py, manifests, the HPA transcript, and a table of cut versus completed streams with and without graceful drain.
Check
Replicas scale from 1 to 4 under load and back to 1 within a few minutes; with graceful drain zero streams are cut; without it every stream on the deleted pod is cut.

Build your own

Build your own autoscaler + load balancer

PythonCPU · your Mac~8 h

A streaming reverse proxy with least-outstanding, least-KV and prefix-aware routing, health ejection and retries, and a queue-depth autoscaler with graceful drain, proven by killing replicas under load.

The real thing: github.com/vllm-project/production-stack ↗

How you know a stage passes

Write tests/test_router.py first. Tests start N copies of the Phase 5 stub streaming server (vLLM metric names, configurable per-token delay, a prefix-cache hit counter) and your router as subprocesses, run the load generator from Phase 3 against the router, and assert on the CSV it writes (per-request status, TTFT, ITL, replica). Chaos tests send SIGKILL to a replica mid-run. Run `pytest -q`; the final stage repeats the key tests against kind with kubectl.

Stages, in order. Each one leaves you with something that runs.0/7
  1. 01a streaming reverse proxy
    The router forwards OpenAI-compatible requests to replicas listed in a config file, streams SSE chunks back as they arrive, and round-robins.
    test · 300 streamed requests across 3 replicas land 100 each (plus or minus 2); the first chunk of a 64-token response arrives at least 100 ms before the last chunk.
  2. 02load-aware routing from scraped metrics
    A background scraper reads vllm:num_requests_running and vllm:gpu_cache_usage_perc from each replica every 200 ms; least-outstanding and least-KV policies use them.
    test · With one replica slowed 3x, least-outstanding p99 latency on a 300-request run is below 50 percent of round-robin p99 on the same run.
  3. 03prefix-aware routing
    Requests hash on session id or the first 256 prompt tokens to a replica via consistent hashing, falling back to least-outstanding when the chosen replica is more than 1.5x the mean load.
    test · On synthetic agent traces the replica-reported prefix hit rate is at least 80 percent versus about 1 / N for round-robin at N=4, while max over min requests per replica stays at or below 1.5.
  4. 04health ejection and retries
    Replicas failing 3 consecutive probes or refusing connections are ejected and re-admitted after passing probes; requests that have not yet produced a first token are retried on another replica.
    test · SIGKILL on one replica during a 500-request run yields zero failed requests among those without a first token, ejection within 2 s, and the in-flight streams that were cut are counted and reported.
  5. 05the autoscaler with graceful drain
    Replica count follows vllm:num_requests_waiting averaged over 15 s with min, max, cooldown and a drain step that stops routing to a replica, waits for in-flight requests, then sends SIGTERM.
    test · A step from 2 to 40 concurrent users scales 1 to 4 replicas within 30 s and back to 1 within cooldown plus 60 s after load stops; no request fails during scale-down.
  6. 06a chaos run with a report
    A 10-minute run kills a random replica every 90 s while the autoscaler and router protect traffic; the report shows replicas, queue depth, error rate and p99 over time.
    test · Availability is at least 99.5 percent with ejection and retries on and measurably lower with them off (both numbers in the README); the plot has the kill times marked.
  7. 07on kind
    The stub server becomes a Deployment with readiness and liveness probes, the router a Deployment plus Service, and the autoscaler patches the Deployment scale subresource through the Kubernetes API.
    test · `kubectl delete pod` on a replica under load reproduces the s4 result; `kubectl get deploy -w` shows replicas moving 1 to 4 and back under the s5 load pattern.

Knowledge check

QWhy is GPU utilisation a poor autoscaling signal for LLM serving?

A single decode batch can show near 100 percent SM utilisation while the server still has headroom; queue depth or KV cache utilisation tracks actual pressure and latency.

QWhat happens to the other ranks when one GPU in a TP=8 group fails?

Their next collective blocks until the NCCL watchdog times out, so the whole group must be torn down and restarted together.

QWhy does prefix-aware routing trade load balance for latency?

Hashing a hot prefix to one replica concentrates its traffic there, so prefill is cheaper via KV reuse but that replica can become a hotspot.

QWhat must terminationGracePeriodSeconds be sized to?

At least the longest expected generation time plus load-balancer deregistration delay so in-flight streams finish before SIGKILL.

Completion

  • All 5 subtopics marked done
  • All 2 required lessons done
  • Lesson l1 simulation produces the policy comparison plot with the expected ordering.
  • Lesson l2 shows scale-up, scale-down, and zero cut streams with graceful drain.
  • Can list three autoscaling signals and rank them for LLM serving with reasons.
Topic progress is derived; it reaches 100% when both checks above pass.Next recommended topic →