---
title: Multi-tenant LLM inference platform
url: https://gurkanozkan.ai/learn/design/applied-llm-sd-06/
markdown: https://gurkanozkan.ai/learn/design/applied-llm-sd-06.md
kind: design
role: Applied LLM
json: https://gurkanozkan.ai/api/learn/design/applied-llm-sd-06.json
---

# Multi-tenant LLM inference platform

Design an internal platform that serves several LLMs (including open-weight models and fine-tuned adapters) to many product teams and external API customers, with per-tenant rate limits, streaming, SLOs and billing.

## What to cover

- **Requirements**: models and sizes; traffic shape (interactive vs batch); SLOs per tier; GPU inventory; adapter count; isolation and residency needs
- **Estimates**
- **API**
- **Data model**
- **Architecture**: gateway (auth, token-based quotas, priority classes); router (model/version/region, adapter placement); per-model serving pools with continuous batching, paged KV cache, prefix caching, chunked prefill; autoscaling with warm pools and model-weight distribution; multi-LoRA serving; batch API path; metering; observability (TTFT/ITL percentiles, queue depth, KV usage, goodput); canary deploys and rollback
- **Deep dives**: one tenant sends huge prompts and starves others — fix it.; How do you roll out a new model version safely?; How many GPUs for X requests/s at given lengths?
- **Trade-offs**: latency vs throughput (batch size); isolation vs utilisation (dedicated vs shared pools); quantisation vs quality; preemption vs fairness; overprovisioning vs cold starts
- **Evaluation**: uses LLM-specific mechanisms (iteration-level batching, KV memory as the binding constraint); back-of-envelope capacity numbers; fairness and backpressure; staged rollout with evals

## Reference design

### Requirements

**Functional**: OpenAI-compatible chat/completions with streaming; several models and versions; customer LoRA adapters; a 24-hour batch API; per-tenant keys, quotas, usage reporting and billing.

**Assumptions to confirm**
- **Models and sizes**: an 8B dense model (cheap tier, most adapters), a 70B dense model (default), a large MoE model (premium); FP8 weights for all.
- **Traffic shape**: ~70% interactive (chat, agents, tool loops with long shared prefixes), ~30% batch (evals, document processing); strong diurnal peaks.
- **SLOs per tier**: premium TTFT p95 < 500 ms for prompts ≤ 4k tokens and inter-token latency (ITL) p95 < 50 ms; standard TTFT p95 < 2 s; batch completes within 24 h; 99.9% availability for paid tiers.
- **GPU inventory**: ~512 H100 80 GB in two regions (EU and US); capacity is fixed for the quarter, so efficiency matters more than elastic cloud scaling.
- **Adapter count**: ~500 LoRA adapters, long-tailed popularity.
- **Isolation and residency**: EU customers served in the EU; external API prompts not logged by default; some enterprise tenants get dedicated capacity; internal teams share pools.
- **Billing**: per input, cached-input and output token, per model.


### Estimates

**70B model, FP8, tensor-parallel over 2 GPUs**: weights 70 GB of 160 GB; ~75 GB left for KV cache. KV per token = 2 × 80 layers × 8 KV heads × 128 dims × 1 byte ≈ **160 KB** → ~460k tokens of KV per replica.

**Workload**: 100 req/s, 2k-token prompts, 300 output tokens.
- **Prefill**: 200k tokens/s × 2 × 70B FLOPs ≈ 28 PFLOP/s; 50% prefix-cache hits → 14 PFLOP/s. An H100 at ~50% of FP8 peak gives ~1 PFLOP/s → **~14 GPUs' worth**.
- **Decode**: 30k tokens/s. One step reads 70 GB of weights at 2 × 3.35 TB/s ≈ 10 ms, plus ~3 ms of KV reads at batch 64 → ~20 ms in practice → 64 / 0.02 ≈ 3k tokens/s per replica → **~10–11 replicas = 22 GPUs**.
- **Little's law check**: each request lives ~7 s (TTFT + 300 × 20 ms) → ~700 in-flight sequences → 11 replicas at batch 64. KV in use: 700 × 2.3k × 160 KB ≈ 260 GB, ~24 GB per replica (of ~75 GB) — comfortable.
- **Total**: ~36 GPUs of work with chunked prefill colocated, +30% headroom → **~48 H100s (24 replicas)** for 100 req/s.

**Long context**: one 128k-token prompt needs ≈ 20 GB of KV, over a quarter of a replica — KV memory, not FLOPs, binds.

**Adapters**: rank-16 LoRA on q, k, v, o of an 8B GQA model (32 layers, d = 4,096, 8 KV heads × 128): 16 × [(4,096 + 4,096) × 2 + (4,096 + 1,024) × 2] ≈ 426k parameters per layer × 32 ≈ 13.6M ≈ 27 MB in BF16; 500 ≈ 14 GB, so keep ~50 hot on GPU and page the rest from host memory.


### API

```
POST /v1/chat/completions        (OpenAI-compatible)
  Authorization: Bearer <tenant key>
  {model: "llama-70b@2026-09" | "llama-8b:adapter_123", messages, max_tokens, stream: true,
   priority?: "interactive"|"background"}
  → SSE deltas; final usage {input_tokens, cached_tokens, output_tokens}
  → 429 {retry_after} when the tenant's token bucket or concurrency cap is exhausted

POST /v1/batches   {input_file_id, model, completion_window: "24h"}  → {batch_id}
GET  /v1/batches/{id}
POST /v1/adapters  {base_model, artefact_uri, rank}   → {adapter_id, status}
GET  /v1/models    (pinned snapshots plus aliases and deprecation dates)
GET  /v1/usage?group_by=model,day

Internal: Router → pool   gRPC Generate{request_id, tenant, model_version, adapter_id,
                          priority, deadline, prompt_tokens, sampling_params}
```
Model names are pinned snapshots; aliases like `llama-70b` move only after a rollout completes.


### Data model

- **Tenant**: tier, quotas (input and output tokens per minute, requests per minute, max concurrency, max prompt length), priority class, residency region, logging policy, dedicated pool reference.
- **ApiKey**: tenant, scopes, rotation dates.
- **Model / ModelVersion**: family, weights URI, quantisation, tokeniser hash, context length, eval report, status (canary | live | deprecated).
- **Adapter**: id, base model version, rank, artefact URI, owner, hotness, compatible pools.
- **Deployment**: pool, model version, region, replica count, traffic weight, rollout stage.
- **UsageRecord**: request_id, tenant, model version, adapter, input/cached/output tokens, TTFT, total latency, status, region, timestamp → Kafka → billing aggregates (idempotent on request_id).
- **RequestLog**: metadata only by default; prompt and response bodies only for tenants that opt in, with retention limits.
- **PoolTelemetry**: per replica queue depth, running sequences, KV utilisation, prefix-cache hit rate, tokens/s.


### Architecture

```
Clients ─► Global LB ─► Gateway: auth, token-bucket quotas on input+output tokens,
             concurrency caps, max prompt size, priority class, residency pinning
   ─► Router: model/version/region; adapter affinity; prefix-cache affinity
             (hash of the first N tokens); least-loaded by KV usage and queue
   ─► Serving pools per model (vLLM / SGLang / TensorRT-LLM):
         continuous (iteration-level) batching · paged KV cache · prefix caching
         · chunked prefill · multi-LoRA kernels · FP8 weights and KV
         per-replica scheduler: priority queues, per-tenant fair share,
         preemption by swap or recompute
   ─► Autoscaler: scales on queue depth, KV utilisation and SLO burn rate;
         warm pool; weights distributed peer-to-peer and cached on local NVMe
Batch path: files ─► batch queue ─► fills idle capacity at lowest priority
Metering ─► Kafka ─► billing · Observability: TTFT/ITL percentiles, queue depth,
   KV usage, goodput · Deploy controller: shadow ─► canary ─► ramp, auto-rollback
```
Dedicated pools for enterprise tenants reuse the same stack with their own replicas.


### Deep dives

**One tenant sends huge prompts and starves others.** Quotas count tokens, not requests, and input tokens weigh by their prefill cost. Cap each tenant's in-flight prefill tokens and concurrency. Chunked prefill (e.g. 512-token chunks interleaved with decode steps) stops a 100k-token prompt blocking everyone's next token. The scheduler does weighted fair sharing of batch slots and KV blocks per tenant, preempting the lowest-priority sequences when KV runs out. Route prompts above ~32k tokens to a dedicated long-context pool. Return 429 with `retry_after` early, before queueing, so backpressure is explicit.

**Rolling out a new model version safely.** Offline gates: quality and safety eval suites versus the incumbent, tokeniser and chat-template diffs, a load test for tokens/s and TTFT. Then shadow traffic from internal tenants (outputs compared, never returned), then canary 1% → 10% → 50% → 100% by tenant cohort with automatic rollback on error rate, TTFT/ITL, refusal rate or online judge scores. External customers stay on pinned snapshots, with deprecation notices.

**GPUs for X req/s.** Compute prefill FLOPs and decode bandwidth separately, check KV capacity with Little's law, then add headroom — the estimates section works 100 req/s on the 70B to ~48 H100s.


### Trade-offs

- **Latency vs throughput (batch size)**: larger decode batches raise tokens per GPU almost linearly until compute-bound, but ITL grows; set max batch per tier from the ITL SLO.
- **Isolation vs utilisation**: dedicated pools give predictable latency and contractual isolation but idle capacity; shared pools with fair scheduling are far cheaper. Offer dedicated only to tenants who pay for it.
- **Quantisation vs quality**: FP8 weights and KV are near-lossless and double capacity; INT4 for a cheap tier only after per-task evals; never change quantisation of a pinned snapshot silently.
- **Preemption vs fairness**: preempting long sequences protects SLOs for many but wastes the recompute; prefer swapping KV to host memory and preempt the lowest priority first.
- **Overprovisioning vs cold starts**: loading 70 GB of weights from local NVMe takes ~15 s plus warm-up, from object storage over a minute; keep a warm pool sized to the peak ramp rate and let batch jobs use it meanwhile.


### Evaluation

- **LLM-specific mechanisms**: iteration-level batching, paged and prefix-cached KV, chunked prefill, multi-LoRA; KV utilisation treated as the binding resource.
- **Capacity numbers**: per-model capacity model (prefill FLOPs, decode bandwidth, KV) validated by load tests; re-run whenever a model or GPU type changes.
- **SLO attainment**: TTFT and ITL p50/p95/p99 per tier and tenant; **goodput** (requests per second meeting their SLO) as the headline metric, not raw throughput.
- **Fairness and backpressure**: per-tenant share of capacity vs entitlement, 429 rates, queue time by priority; noisy-neighbour load tests in CI.
- **Staged rollout with evals**: every model version has an eval report, a canary record and a rollback runbook; online judge scores and refusal rates compared with the incumbent.
- **Business**: cost per million tokens per model, GPU utilisation, prefix-cache hit rate, billing reconciliation (metered tokens vs serving logs within 0.1%).


## What a strong design shows

- Uses LLM-specific serving mechanics — continuous batching, paged and prefix KV caching, chunked prefill, multi-LoRA — and names KV memory as the binding constraint.
- Does the capacity arithmetic: prefill FLOPs, decode bandwidth, Little's law for concurrency, then headroom.
- Gives quotas in tokens, fair scheduling and explicit backpressure so one tenant cannot starve others.
- Rolls out models through offline gates, shadow, canary and automatic rollback, with pinned snapshots for API customers.
- Measures goodput against per-tier SLOs rather than average latency.

---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
