Label: request/response with real-time streaming, plus a routing layer over a pool of scarce, uneven workers.
Clarify
- Which endpoints: chat completions, embeddings, both? Streaming required?
- Latency targets: TTFT p95 under 1 s? Different tiers (priority vs best effort)?
- How many models, and how skewed is traffic? (Usually a few models take most of it.)
- Multi-tenant on shared replicas, or does anyone get dedicated capacity?
- Is cost per token a first-class goal? (Yes. Say so.)
Numbers
10M tokens/s across the fleet. Assume one 8-GPU node serving a 70B-class model does around 20k tokens/s blended (state it as an assumption): that's ~500 nodes, ~4,000 GPUs. GPUs are the cost, so every design choice is about keeping them busy without blowing TTFT. The control traffic itself (10k requests/s) is small for the gateway.
Sketch
Clients call POST /v1/chat/completions with an API key. The gateway authenticates, applies per-key limits in tokens per minute as well as requests, checks the account has credit, and holds the SSE stream open. A router looks up the model in the catalog, picks a pool and a replica using health, queue depth and KV cache headroom, preferring the replica that already has the prompt's prefix cached. Each pool has a priority queue in front so the router can admit, queue or reject. Model servers (vLLM/SGLang) run continuous batching and stream tokens back. Overflow goes to brokered capacity behind the same interface. At the end of each request the server emits a usage event (tokens in, tokens out, model, account, request_id) to metering.
Deep dives
Rate limiting in tokens, not requests
Example One customer sends 100 requests/min with 100k-token prompts. Request limits say fine; the GPUs say no.
Default answer Token-bucket per key on estimated tokens (prompt length + max_tokens), reserved at admission and corrected when the request finishes. Keep counters in Redis per region; small overshoot is acceptable.
Routing: load vs cache affinity
Example An agent sends a 30k-token conversation that grows each turn. On the same replica, the prefix is cached and TTFT is 200 ms; on a random one, it's 3 s.
Default answer Consistent hashing on a prefix hash (or session id) to pick a preferred replica, with a load check: if it's overloaded, fall back to the least-loaded replica. Affinity is a hint, never a requirement.
Overload: queue, shed or degrade
Example A new model launches on day 0 and traffic is 5× what was provisioned.
Default answer Bounded queues per pool and priority tier; reject fast with 429 and Retry-After when the queue's expected wait exceeds the TTFT budget; spill to brokered capacity. Never switch to a quantized model without telling the customer.
Failure mid-stream
Example A partner node dies after streaming 400 tokens.
Default answer You can't transparently retry a half-sent stream. Send an error event, bill the tokens actually delivered, and let the client retry. Health checks and draining keep this rare; replicas are cattle.