Design decisions
The leader/worker pattern
Why each endpoint has its own leader, why workers join it, why the control plane stays off the request path, and what that costs compared with a shared router, a mesh or a Service per model.
Every endpoint is one leader and the workers that join it. The leader is core's opod up process: it takes the OpenAI requests for one model and sends each to a worker. A worker is core's opod join process beside one inference engine on its GPUs. The control plane writes what the leader needs into files in the leader's pod, and then stays out of the way.
clients ──► leader of endpoint "chat" ──► worker 1 (vLLM, GPU 0)
keys, admission, routing, worker 2 (vLLM, GPU 1)
usage, streaming gang A (head + 2 parts)
▲
│ mounted files: plan, auth snapshot, policy
opodcp ─────────┘ (writes them; never sees a request)In short
- One leader per endpoint, one model per leader. Two models are two endpoints with two leaders.
- Scale means more workers or gangs under the same leader, never a second leader.
- The control plane is never on the request path. The leader reads its plan, keys and policy from files Kubernetes keeps in its pod. With every control-plane replica down, endpoints keep serving.
- A failure stays inside one endpoint. A bad leader, a bad plan or a bad image touches the model it serves and nothing else.
What the leader does on every request
All of it runs in the leader process, in memory, with no call to the control plane or a database:
- Checks the key against the auth snapshot mounted from the endpoint's Secret. A revoked key arrives as a tombstone in the next snapshot. See API keys.
- Admits the request by worker slots. Each worker reports on its heartbeat how many requests its engine serves at once. The leader dispatches a request only while a worker has a free slot, and holds the rest in its own queue:
criticalbeforestandardbeforesheddable, fair share inside a class. An engine's own queue is first-come and cannot rank requests; the leader's queue can. - Picks a worker. The score is the worker's in-flight requests plus its queue depth, read from heartbeats every 5 s. The policy can add KV-cache use (
kvWeight, off by default) and prefix affinity, so a long shared prompt lands where it is already cached. A worker at its saturation threshold gets a request only when no other worker has room. See Routing. - Streams the answer and records one usage row: tokens in and out, time to first token, which worker served. Usage records start only at the leader.
The request path of one endpoint
Pick a failure and watch where requests go
Why this shape
The request path must not depend on the control plane
A control plane is a large program that changes often. It has a database, an upgrade, a leader election. If a request had to ask it anything, every one of those would be a way to lose traffic. So the request path needs only what the leader pod already holds:
| The leader reads | From | Who writes it |
|---|---|---|
| the plan (model, workers, gangs) | a ConfigMap mounted as a file | the control plane |
| keys, tombstones | a Secret mounted as a file | the control plane |
routing and admission policy (policy.json) | the same Secret | the control plane |
| live load of each worker | worker heartbeats, every 5 s | the workers |
The kubelet keeps those files in the pod whether or not the control plane runs. This is static stability: when the part that makes changes is down, the part that serves keeps the last good state and serves from it. What stops during an outage is change: new endpoints, plan edits, rollouts, and the embedded autoscaler. See What survives an outage.
One model per leader gives every endpoint its own blast radius
A leader knows one model, one set of workers and one set of keys. That makes several things simple:
- A failure is per endpoint. A leader crash, a wrong flag, or an engine that leaks memory costs that endpoint. The other endpoints in the cell do not share a process with it.
- Policy is per endpoint. Admission holds, request classes, routing weights and canary splits apply to one model's traffic, where their numbers mean something.
- Rollouts are per endpoint. A new image or engine version is proven on one endpoint and rolled back on one endpoint.
- Load signals are per model. "In flight", "queue" and "KV pressure" describe one model on one kind of worker, so the autoscaler can act on them directly.
The leader is where scale-to-zero becomes possible
The leader holds no GPU, so it stays up when every worker is parked. The URL keeps answering, and a request that arrives counts as demand that wakes a worker. Today a leader with nothing awake answers 503 with Retry-After, and that refusal is the wake signal. In 0.3.0 a plan with floor: 0 raises the leader's admission hold to 60 s, so the client waits through the wake instead. See Autoscaling → Tiers of idle.
Gangs are workers too
A model too big for one machine runs as a gang: one engine instance split across several pods. Every part runs opod join and heartbeats like any worker. The gang's head is a worker rank, never the leader. To the leader a gang is one routing target, ready only when every part reports. One lost part takes that gang out of rotation while the other gangs and workers keep serving. Several gangs of one model live under one leader, and the router picks the least loaded ready gang. With the LeaderWorkerSet controller, a gang lands and restarts as one unit. See Gangs.
Workers are disposable, and named by what they are
A worker holds no record. If its pod dies, the leader routes to the others and the reconciler replaces the pod. Each worker process mints a boot id when it starts and sends it on every heartbeat. A new boot id under the same node id is a new process: the leader drops the old process's placements and gang rows at once, instead of routing to a pod IP that no longer exists. A worker that gets 401 on a heartbeat (the leader restarted) re-registers with the token it holds, so a leader restart costs one registration per worker.
Front doors and the cell door
Two optional pieces cover the two weak spots of "one leader process per model".
- Front doors (
plan.gateways.enabled) are stateless copies of the leader's request path for one endpoint (opod up --role gateway). They check keys and route to the leader's workers themselves. There is still one leader: it alone owns the worker registry, join tokens and gangs. Doors push their usage rows to the leader, the single writer. With doors on, a leader restart costs no requests, from core v0.4.0. In v0.3.0 a door read the restarted leader's still-empty worker list as final and answered 503 until its next sync: 16 of 60 requests in one test. Now the leader marks that list as rebuilding, and the door keeps routing to the workers it knew. - The cell door (
door.enabled) is one URL for many endpoints (opod up --role door). It readsmodel, looks up the endpoint by alias, and forwards the request unchanged. It picks no worker and holds no credential: the endpoint's leader still checks the key and routes. On the design-partner cell it added 0.6 ms at p50 and 1.4 ms at p95 over the direct path.
See Front doors and cell doors.
What it costs
| Cost | Size | What we do about it |
|---|---|---|
| A leader is one process per endpoint. When it restarts, the requests in flight on it are lost. | Kubernetes restarts it in about 10 s. Workers re-join through the Service name. | Front doors: max(2, ceil(units/4)) door pods with anti-affinity, where a unit is one worker or one gang, so a restart costs no requests. |
| Every request takes one extra hop: client → leader → worker. | about 0.2 ms per round trip across nodes, measured; about 8 ms more for each new TLS connection | Leaders and doors are placed by a fixed rule the control plane decides. |
| Many endpoints means many leader pods. | one small pod per endpoint, no GPU | Doors hold no card and are not counted by the ledger, the licence or a quota. |
| No leader routes to another endpoint. "Try model B when model A is busy" is not a leader feature. | — | The cell door's auto routes do it in your order; a gateway such as LiteLLM can too. |
| The worker load the leader sees is one heartbeat old. | up to 5 s for queue and KV use | In-flight is the leader's own live count; a slot is granted only on completion. |
| No worker is ever promoted to leader, and two leaders never run at once. | an outage of one endpoint is as long as one pod restart | This is a deliberate trade: no split-brain code, and nothing to fail over by hand. |
Compared with other shapes
Each of these is a reasonable design. They solve different problems, and some combine with opod.
| Shape | What it does well | What it costs for self-hosted inference | With opod |
|---|---|---|---|
| One central gateway or router for all models | One URL, one place for keys, budgets and logs. Simple for clients. | One process or pool in front of every model: its failure or bad config touches them all. It usually sees requests, not the engines' slots, queues or KV caches. | Use it in front. LiteLLM holds per-user keys and budgets; each opod leader still picks the worker. See Use with LiteLLM. |
| A service mesh (Istio, Linkerd) | mTLS, retries, traffic splits and telemetry for any service, with no code change. | Balances by connections or requests. It does not know that one worker's KV cache is full or that a gang is one target, and a long stream looks like one request. | Run it if you already do. The leader still decides which worker serves. |
| KV-aware inference routers (llm-d's endpoint picker on the Gateway API, NVIDIA Dynamo's router) | Routing that reads queue, KV use and cached prefixes, designed for large fleets of one model, with prefill/decode split. Strong, actively developed projects. | More components to install and run (a gateway, a picker, their own control surfaces). They route; placement of models on measured VRAM, licences and rollouts are left to you. | In 0.3.0 a leader can join a Gateway API InferencePool: the gateway picks a leader, the leader picks a worker. The leader publishes vLLM-named metrics for the picker. See Gateways → InferencePool. |
| One Kubernetes Service per model | Nothing to install. Every Kubernetes user knows it. | kube-proxy spreads connections, not requests, and knows nothing about load. A Service with no ready pod refuses the connection, so scale-to-zero needs something else in front. A multi-pod gang is not one target. | The leader's Service is exactly this, one level up: clients reach the leader by a stable Service name, and the leader does what a Service cannot. |
Read more
- Architecture: what runs where.
- Routing policy, doors and admission: every knob the leader reads.
- Core concepts: the same pattern run by hand with
opod upandopod join.
Last updated · Source: content/docs/design/leader-worker.mdx · View as Markdown