Pidoku

Routing Strategies

Module 21 Lesson 21.g 1h 15m Difficulty 4/5

Prerequisites 20.f, 21.b, 21.f


Before you start: words you need#

WordPlain meaning
RouterThe data-plane component that decides where each request goes.
PoolA group of replicas of one model, tuned for one kind of traffic (general chat, long context, batch).
AliasA client-facing model name, such as chat-large, that the registry maps to a real model version (21.b).
Endpoint pickerIn the Kubernetes Gateway API Inference Extension, the service a gateway asks “which pod should take this request?”
LoRA adapterA small set of extra weights that turns a base model into a fine-tune; many can share one server (18.g, 20.i).
AdmissionDeciding whether to accept a request now, queue it, or reject it.
TTFTTime to first token: how long the user waits before the answer starts.

1. What is it?#

A platform router makes several decisions for every request, in order:

1. WHICH MODEL?      alias resolution, canary split, cascades and fallbacks
2. WHICH POOL?       general / long-context / premium / batch / canary
3. WHICH REPLICA?    load-aware, prefix-aware, adapter-aware
4. ADMIT OR REJECT?  quota, capacity, priority, deadline

Load balancing between replicas of one model (decision 3, the basics) is in 20.f. Choosing a replica by prefix cache in depth is 21.h. This lesson covers the platform-level decisions around them: which model, which pool, admission, the routing table, multi-LoRA and failure handling.

Facts checked on 13 November 2026.


2. Why does it matter?#

Each decision protects something different:

  • Which model decouples clients from deployments, so models can change without client releases.
  • Which pool protects latency: one 128k-token request in a pool tuned for 4k chat holds the KV memory of 32 normal requests and a long prefill that everyone on that replica feels.
  • Which replica decides cache hit rates and batch sizes, so it decides cost per token.
  • Admission decides whether overload turns into fast, honest rejections or into timeouts for everyone.

A router that gets the pool decision wrong cannot be rescued by a clever replica choice.


3. Simple analogy#

An airport. Check-in (gateway) confirms who you are. The departures board (alias) maps “flight to Paris” to a specific aircraft. Security has separate lanes: standard, priority, oversized luggage (pools). Within a lane, staff send you to the shortest queue (replica). When the airport is full, the desk stops checking people in rather than letting them queue for a flight that will not leave (admission).


4. Tiny example: one long-context pool#

A fleet of 8 replicas gets 70 requests per second. 98% are 2,000-token prompts, 2% are 64,000-token prompts. Each replica prefills 40,000 tokens per second. Section 6 simulates three layouts:

one pool of 8          short: p50  50 ms  p99  518 ms   long: p50  1600 ms  p99  2070 ms
5 general + 3 long     short: p50  50 ms  p99  105 ms   long: p50  1768 ms  p99  5374 ms
7 general + 1 long     short: p50  50 ms  p99   67 ms   long: p50 1756719 ms  p99 3505723 ms
  • Mixing them makes 1 in 100 short requests wait behind a 1.6-second prefill: p99 is 10x p50.
  • A separate long-context pool cuts short-prompt p99 by about 5x. Long requests wait longer (p99 5.4 s instead of 2.1 s), which users who sent 64,000 tokens accept far more easily.
  • Size the long pool from its own load. 2% of requests is 1.4 per second × 1.6 s = 2.24 replicas of work. Give it one replica and the queue grows without limit.

5. Technical explanation#

Decision 1: which model#

ALIAS RESOLUTION    "chat-large" → chat-general v1.5.0                      (21.b)
VERSION SPLIT       canary: 5% → v1.6.0, 95% → v1.5.0, sticky per conversation (20.j)
COST-AWARE CHOICE   easy queries → the small model, hard ones → the large one (21.k)
TENANT RULES        tenant has a fine-tune → the pool serving that LoRA adapter;
                    tenant restricted to certain models → enforce here

On Kubernetes the pieces have names. A gateway route matches on the model field after body-based routing (BBR) copies it from the JSON body into a header (the gateway cannot route on a JSON field directly). Weighted splits between versions are expressed as an InferenceModelRewrite. With Gateway API Inference Extension v1.6.0 (17 August 2026), the full endpoint picker, InferenceModelRewrite and InferenceObjective moved into the llm-d Router, and BBR into llm-d’s inference payload processor. The Inference Extension itself now keeps the InferencePool API, the endpoint picker protocol, a lightweight reference picker and the conformance tests (21.j). Choosing a model by what the query is about is done by a semantic router, such as the vLLM Semantic Router project, in front of the pools (21.k).

Decision 2: which pool#

POOLS
  general        most traffic; tuned for typical request shapes
  long-context   prompts above ~16k–32k tokens; larger max_model_len, fewer sequences,
                 bigger token budget per step (20.d)
  premium        reserved capacity, smaller batches, better inter-token latency
  batch          no latency SLO; huge batches; may use spare or spot capacity
  canary         the version under test

RULES, IN ORDER
  if prompt_tokens > 16000:        → long-context
  elif tenant.tier == "premium":   → premium
  elif request.priority == batch:  → batch
  elif canary_selected(request):   → canary
  else:                            → general

Long-context segregation is the single most valuable routing rule (section 4). It is one line of routing and it protects the p99 of every other request. Disaggregated serving (14.j) is the deeper version of the same idea: separate the phases, not only the request sizes.

Decision 3: which replica#

The platform version of 20.f adds the multi-model and multi-tenant dimensions:

choose_replica(request, model, pool):
    candidates = routing_table[model][pool], minus not-ready and draining replicas
    1. adapter affinity     if the request names a LoRA adapter, prefer replicas holding it
    2. prefix affinity      prefer replicas likely to hold this prompt's prefix,
                            unless they are much busier than the rest           (21.h)
    3. load                 otherwise power of two choices on a load score       (20.f)

load_score(r) = 0.6 × KV cache use + 0.3 × queue depth / max queue + 0.1 × running / max batch

In 2026 you rarely write this from scratch. The Gateway API Inference Extension’s endpoint picker (the full version now lives in llm-d), Dynamo’s router and SGLang’s model gateway all implement scored replica selection with filters and weighted scorers you configure (21.j).

Decision 4: admit or reject#

The router’s admission is a coarse, early check. The engine’s is the authoritative one.

ROUTER (cheap, early, uses slightly stale data)
  tenant over quota?                          → 429 with Retry-After       (23.j)
  every replica of this model at capacity?    → queue briefly (flow control), else 503
  estimated wait > the client's deadline?     → 503 now, not a timeout later
  malformed or over limits?                   → 400                         (20.b)

ENGINE (authoritative, per step)               (20.c)
  is there KV space right now?
  does this fit in this step's token budget?

The router’s view of capacity is a few seconds old. It should be conservative, and the engine must still be able to say no. Never let the router promise what the engine cannot deliver.

The open routers now include flow control: a short, fair, priority-aware queue in the router that admits requests as replicas free up, instead of either rejecting immediately or piling requests onto full replicas (21.f). Keep it short. A long queue in the router hides overload from the autoscaler and from the engines’ schedulers, which have better information.

The routing table#

STRUCTURE
  alias → model_id, version(s), weights
  model_id + version → pools
  pool → [replica endpoints, capabilities, loaded adapters, current load]

DISTRIBUTION (21.a)
  computed by the control plane, pushed to routers, cached with last-known-good
  load metrics collected separately and much more often

FRESHNESS
  which replicas exist        seconds to minutes: slow is fine
  how busy they are           1–5 seconds: matters
  which prefixes they hold    seconds; approximate is fine (21.h)

Load data must be fresher than the replica list. A router with a five-minute-old replica list and current load data works; the reverse does not. In Kubernetes the replica list comes from watching the InferencePool’s pods; load comes from scraping each engine’s metrics endpoint (19.c) or from events the engines publish.

Multi-LoRA routing#

request names adapter "team-x-v3"
  → prefer a replica that already has it loaded (no load delay)
  → concentrate requests for one adapter on few replicas
    (fewer distinct adapters per batch → less adapter-switching overhead in the kernels)
  → if no replica has it, pick the least-loaded replica with a free adapter slot

Adapter affinity is worth some load imbalance, for the same reason prefix affinity is.

Failure handling#

REPLICA STATE                  ACTION
not ready (loading, warming)   exclude
saturated (KV cache full)      DEPRIORITISE, or exclude only while others have room
failing health checks          exclude and alert
draining                       exclude for new requests only

ALL REPLICAS SATURATED         short flow-control queue, then 503 with Retry-After
MODEL NOT DEPLOYED             cold-tier model: trigger a load, hold or reject with a long
                               Retry-After (21.e); unknown model: 404
CONTROL PLANE UNREACHABLE      keep the cached routing table, alert, keep serving (21.a)

“Deprioritise, don’t exclude” prevents cascading failure. Excluding saturated replicas moves their load to the rest, which then saturate, and the router ends with nowhere to send anything. Real routers soften the filter instead of dropping it. The llm-d Router’s default saturation filter (utilization-detector) removes replicas whose metrics are older than 200 ms, whose waiting queue is 5 or more, or whose KV cache is 80% or more full, but when that would remove every replica it keeps them all, and flow control then holds the excess. That last rule is what turns an exclusion into a deprioritisation.


6. Under the hood: simulating pool segregation#

Each replica prefills one prompt at a time and the router sends each request to the replica that will be free soonest. That simplifies chunked prefill (12.k), which interleaves prompts, but the queueing effect is the same.

Go
// pools.go — does a 2% stream of 64k-token prompts hurt everyone else's time to first token?
// Each replica prefills one prompt at a time (a simplification of 12.k's chunked prefill),
// and the router sends each request to the replica with the least queued work.
package main

import (
	"fmt"
	"math"
	"math/rand/v2"
	"slices"
)

const (
	tokensPerSec = 40000.0 // prefill speed of one replica
	shortTokens  = 2000
	longTokens   = 64000
	longShare    = 0.02
	ratePerSec   = 70.0 // arrivals across the whole fleet
	requests     = 200000
)

type replica struct{ freeAt float64 }

// route returns the replica (from the given set) that will be free soonest.
func route(rs []*replica) *replica {
	best := rs[0]
	for _, r := range rs[1:] {
		if r.freeAt < best.freeAt {
			best = r
		}
	}
	return best
}

func p(xs []float64, q float64) float64 {
	slices.Sort(xs)
	return xs[int(q*float64(len(xs)-1))]
}

func run(name string, general, long int) {
	rng := rand.New(rand.NewPCG(3, 4))
	all := make([]*replica, general+long)
	for i := range all {
		all[i] = &replica{}
	}
	genPool, longPool := all[:general], all[general:]
	if long == 0 {
		longPool = genPool // one shared pool
	}
	var clock float64
	var shortTTFT, longTTFT []float64
	for i := 0; i < requests; i++ {
		clock += -math.Log(1-rng.Float64()) / ratePerSec // Poisson arrivals
		isLong := rng.Float64() < longShare
		tokens, pool := float64(shortTokens), genPool
		if isLong {
			tokens, pool = longTokens, longPool
		}
		r := route(pool)
		start := math.Max(clock, r.freeAt)
		r.freeAt = start + tokens/tokensPerSec
		if isLong {
			longTTFT = append(longTTFT, (r.freeAt-clock)*1000)
		} else {
			shortTTFT = append(shortTTFT, (r.freeAt-clock)*1000)
		}
	}
	fmt.Printf("%-22s short: p50 %3.0f ms  p99 %4.0f ms   long: p50 %5.0f ms  p99 %5.0f ms\n",
		name, p(shortTTFT, 0.5), p(shortTTFT, 0.99), p(longTTFT, 0.5), p(longTTFT, 0.99))
}

func main() {
	run("one pool of 8", 8, 0)
	run("5 general + 3 long", 5, 3)
	run("7 general + 1 long", 7, 1) // the long pool is overloaded: 2.24 replicas of work, 1 replica
}

Output:

one pool of 8          short: p50  50 ms  p99  518 ms   long: p50  1600 ms  p99  2070 ms
5 general + 3 long     short: p50  50 ms  p99  105 ms   long: p50  1768 ms  p99  5374 ms
7 general + 1 long     short: p50  50 ms  p99   67 ms   long: p50 1756719 ms  p99 3505723 ms

The total work is 5.67 replicas’ worth (3.43 short, 2.24 long) on 8 replicas, so every layout has enough capacity in total. What changes is who waits behind whom.


7. Performance implications#

  • The router’s own latency is paid by every request. Scoring a few dozen replicas should take well under a millisecond; tokenising long prompts for prefix matching can take more, so do it once (the gateway, 21.i) and pass the tokens along.
  • Stale load data makes load-aware routing worse than random. With 30-second-old numbers, every router sends traffic to the replica that was idle, together. Power of two choices and 1–5 second freshness avoid this (20.f).
  • Pools trade sharing for isolation. Each extra pool needs its own headroom; too many pools, each lightly loaded, waste GPUs. Three to five pools per busy model is typical.

8. Production implications#

  • Adopt an endpoint picker and configure it (llm-d, Dynamo, SGLang’s gateway) before writing a router. Extend it with plugins where your policy is unusual.
  • Segregate long-context requests, and size that pool from its own measured load.
  • Affinity with a release valve, for conversations, prefixes and adapters.
  • Keep load metrics fresh (1–5 s) and alert when they go stale.
  • Deprioritise saturated replicas; never exclude them.
  • Keep the router’s queue short, and let the autoscaler see the overload.
  • Log every routing decision: which replica, why, and the runner-up. When routing goes wrong you need to see the decision, not just the outcome.

9. Common mistakes#

  1. A generic round-robin load balancer in front of LLM replicas (20.f).
  2. No long-context pool, or one sized as “one replica, because it is only 2%”.
  3. Excluding saturated replicas with no fallback when all of them are saturated. Cascading failure.
  4. A long queue in the router. It hides the overload and adds a second queue in front of the engine’s.
  5. Stale load metrics.
  6. Affinity without a release valve. One popular conversation or adapter overloads a replica.
  7. Routing on the model name with a JSON-unaware gateway, so every model goes to one pool.
  8. No record of why a request went where it did.

10. Hands-on exercise#

  1. Run pools.go. Try 6 + 2 and 4 + 4. Which layout gives the best short-prompt p99 while keeping long-prompt p99 under 4 seconds?
  2. Change the mix. Make long prompts 5% of traffic, then 0.5%. When does a separate pool stop being worth it?
  3. Exclude vs deprioritise. Extend the simulation so a replica whose queue exceeds 2 seconds is either excluded or given a penalty. Raise the arrival rate step by step and show where the excluding version collapses.
  4. Stale metrics. Make the router see each replica’s freeAt from 1, 5 and 30 seconds ago. At what staleness does it do worse than random choice?
  5. On a cluster. Put two vLLM pools behind a gateway that implements the Inference Extension, route by prompt length, and measure p99 TTFT with a mixed trace.

11. Interview questions#

  1. What decisions does a platform router make, and in what order?
  2. Why segregate long-context requests, and how do you size the long pool?
  3. Why deprioritise rather than exclude a saturated replica?
  4. Where should requests wait when every replica is busy, and for how long?
  5. How fresh must load metrics be, and what goes wrong when they are stale?
  6. How does multi-LoRA change replica selection?
  7. How do you route on a model name that is inside a JSON body?

12. Further reading#

Checked on 13 November 2026.

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in