Unit 3 of 12 · about 4 hours · explain, implement
Router and load-balancer responsibilities, token- and cache-aware routing
Round-robin across replicas collapses tail latency on heterogeneous LLM requests. Placement must see tokens, prefixes and adapters, not just connection counts.
You'll be able to
- Separate router placement (per-request, model and cache aware) from load balancing (system-level capacity spreading).
- Implement prefix-hash routing with bounded imbalance and a FailOpen fallback for picker failure.
- Route LoRA traffic by adapter residency so adapter swaps stay off the critical path.
Covers
Read
In this order, only the parts listed
0 of 5 done
- Load balancing and request routingMachine Learning Systems, Volume 2 - Inference at Scale and Serving Fault Tolerance
Load Balancing and Request Routing: The power of two choices with Algorithm 2 and equation 13, Weighted and adaptive load balancing, Least-connections load balancing, Consistent hashing for stateful routing with Example 1.15, and Health checking and failover with the liveness, readiness and deep levels plus Table 31 cadences (page read 2026-10-14)
- Gateway API Inference Extension routingGateway API Inference Extension
Introduction: Key Features (model-aware and smart load balancing), API Resources, Request Flow five steps; InferencePool page at /api-types/inferencepool:
vllm-qwen3-32bexample withendpointPickerRefandfailureMode: FailOpen; API Reference at /reference/spec:EndpointPickerFailureMode(FailOpen forwards, FailClose drops, default FailClose); Implementer's Guide at /guides/implementers: the EPP callout with thex-gateway-destination-endpointheader (page read 2026-10-14) - Day 24 routing, load balancing and queueing notebook100 Days of LLM Inference - Days 22 to 26
Part 1 token-aware routing (load CV 0.066 to 0.005 over 1000 requests on 4 replicas), Part 2 cache-aware routing (hit rate 8.8% to 30.7%), Part 3 LoRA-aware routing (804 round-robin swaps against 280 LoRA-aware in the stored run, at 200ms each; the LoRA-aware count shifts by a few tens on rerun because NumPy is not reseeded), Part 5 Little's law table and the 80% utilization rule
Use the simulator cells as runnable claims, not as production code. Replace the fixed 200ms swap and 90% sharing with your own workload numbers.
- vLLM LoRA serving and adapter accountingvLLM Online Serving, Architecture and Production Metrics
Instrumentator APIs, LoRA dynamic loading:
/v1/load_lora_adapterand/v1/unload_lora_adapter, local development only; Metrics APIs:/metrics, where the Production Metrics page listsvllm:lora_requests_infoDo not use the dynamic load endpoints outside local development. Production adapter placement belongs in the router.
- Router versus load balancer and smart routingInference Engineering - Chapter 7, Production
Section 7.2.3 (printed pp. 190-191): router as request-level placement versus load balancer as system-level capacity, token-aware and KV-aware routing, LoRA-aware routing, FIFO and priority queues
Focus on
- The router answers per request where it should go (model name, prefix overlap, adapter residency, priority). The load balancer answers where it could go (healthy endpoints with headroom). Mixing the two jobs hides placement bugs behind connection counts.
- Two-choice routing cuts the worst queue from to with one extra probe, but only when the work signal matches LLM load: active tokens or KV pressure, not request count.
- Prefix affinity needs the full identity in the hash key: prompt bytes plus model version, tenant scope and cache salt. Hashing raw text alone reuses across versions and tenants.
- The picker is a single point of failure.
FailClosedrops every request when the picker fails;FailOpenfalls back to gateway-picked endpoints. Choose explicitly per pool.
Common mistakes · 3
- Calling round-robin fair on 10-token and 100000-token requests. Equal counts are unequal load; the long request pins its replica while short ones queue elsewhere.
- Leaving the default
FailCloseunexamined. A picker bug then becomes a full outage for that pool;FailOpentrades it for unplanned placement. - Using
/v1/load_lora_adapterin production. The docs mark it local-development only; live adapter swaps belong in deployment and router affinity, not in request-time calls.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Why does token-aware two-choice routing beat least-connections on LLM load?Answer
Least-connections counts requests, so one 500-token decode counts the same as one 10-token reply. Token-aware two-choice compares post-admission load in tokens or KV pages, exposing the real remaining work.
2.The endpoint picker crashes under
FailClose. What do clients see, and what changes underFailOpen?AnswerUnder
FailClosethe gateway drops requests even though replicas are healthy. UnderFailOpenit forwards to a gateway-picked endpoint, trading smart placement for availability.3.Two tenants share a system prompt. Why must the prefix-hash key include tenant scope?Answer
Otherwise tenant B hits tenant A's cached prefix, leaking prompt bytes through timing and breaking isolation. Salt or scope the key per tenant.
4.LoRA-aware routing cut swaps from 804 to about 280 in the stored run. What does each avoided swap save?Answer
One 200ms adapter load off the request path, plus the KV and batch disruption around it. Affinity keeps hot adapters resident instead of churning them.
Practice
- 100 Days day24: routing experiments 1 and 3
Try These Experiments: 1, consistent-hash ring under rolling restart with 1/N movement; 3, LIFO versus FIFO tails under a 10x burst
Run experiments 1 and 3 in the notebook (experiment 2 is the overload unit's breaker drill), then port the hashing ring to your own gateway sketch with model version and tenant in the key.
You're done when
Your simulation shows the CV drop, your hash key names version and tenant, and you can defend FailOpen versus FailClose for one pool.
Only when you can do this without notes.
Leads to
Notes
Resources · 5 for this unit, 8 more in the section
- vLLM Online Serving, Architecture and Production MetricsvLLM Project · primary
Trace the API server, engine core, scheduler, KV manager and model runner, then map documented metrics to your SLIs. The link is pinned to v0.31.0; add the auth, tenant, quality and rollout controls the engine leaves to you.
- Machine Learning Systems, Volume 2 - Inference at Scale and Serving Fault ToleranceHarvard (Vijay Janapa Reddi) · required
Read "Load Balancing and Request Routing", "Multi-Tenancy and Isolation" and "Autoscaling and Global Infrastructure" in Inference at Scale, then "Serving Fault Tolerance" and "Graceful Degradation" in the Fault Tolerance chapter.
- Inference Engineering - Chapter 7, ProductionPhilip Kiely (Baseten Books) · support
Read Chapter 7 for containers, autoscaling, cold starts, routing and queueing, zero-downtime deployment, cost estimation and client-side streaming. Skip the vendor section at its end.
- Gateway API Inference ExtensionKubernetes SIG Network · required
Study model-aware routing, endpoint selection and operational integration. Use it for architecture and an optional local deployment only after the service passes lifecycle and failure tests without Kubernetes.
- 100 Days of LLM Inference - Days 22 to 26Elizabeth Thomas · support
Use the container, autoscaling, routing, capacity and zero-downtime notebooks as small operational simulations. Replace calendar order and fixed scale targets with the stage checkpoint and your hardware limits.
Also in this section
- Hands-On LLM Serving and Optimization - Chapters 3 and 4, serving system designChi Wang and Peiheng Hu (O'Reilly) · required
Read Chapter 3 (an online service from scratch, batching with streaming, multi-model trade-offs) and the enterprise-architecture part of Chapter 4. Convert the designs into explicit request, model-lifecycle and failure state machines.
- vLLM Production MetricsvLLM Project · required
Define every selected queue, cache, phase and request metric, check histogram buckets and measure exporter overhead. Add model version, cancellation, rejection, quality sample and tenant-safe trace fields in the surrounding service.
- SGLang documentation - Production MetricsSGLang Project · support
Compare its metric names and phase boundaries with vLLM's, so your dashboards do not depend on one engine's vocabulary.
- AI Systems Performance Engineering - Production Inference LabsChris Fregly · required
Use Chapter 16 monitoring, cache health, capacity planning and load-test utilities, then Chapter 17 routing only if distributed. Add process death, overload and bad-version cases that the performance pairs do not cover.
- AI Infrastructure Engineer Learning - Project 103 LLM DeploymentAI Infra Curriculum · support
Use its Docker, API, monitoring, Kubernetes and cost files as scaffolding only. Check its resource assumptions against your own model and GPU, and rerun any benchmark before reusing a result.
- LLM Inference Systems Laboratory - Operations and FailureRoadmap-Final · support
Complete production gateway, isolation, telemetry, canary, drain, rollback and fault campaigns. Store first-cause timelines and revise runbooks from observed blind spots.
- OpenAI API Reference - streaming, auth, rate limits and request IDsOpenAI · reference
Read the chat streaming event shape with the
[DONE]terminator, bearer auth, rate-limit headers, andx-request-idwith caller-suppliedX-Client-Request-Id. vLLM is the implementation under test; use this only for the contract it claims compatibility with. - vLLM Multimodal Inputs - media validation, fetch policy and cache identityvLLM Project · reference
Read Online Serving for image, video and audio inputs:
--allowed-media-domains, fetch timeouts,--limit-mm-per-prompt, local-media path restriction, and media UUIDs for cache identity. The link is pinned to v0.31.0.