B.9 Pass 7: The Serving Platform
This pass replaces the tracer’s engine and gateway with production ones and runs them the way a production platform would. The Rust engine, written with async Rust, tokio, and hyper, gains continuous batching, chunked prefill, a prefix-caching block manager, disaggregated prefill and decode connected by gRPC, serving metrics and tracing, speculative decoding, and tool calls. A load generator measures it. The Go gateway in front gains authentication and authorization, rate limits, a streaming proxy, consistent-hash routing with cascades and failover, a response cache, and a usage ledger in SQLite that reconciles with what the engine reports.
Concepts from other sections (29)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- continuous batching: re-forming the batch at every step so finished requests leave and waiting ones join immediately. Read more: 23.3 Continuous batching scheduler with priority and preemption
- chunked prefill: prefilling a prompt over several steps in pieces of at most
prefill_chunktokens, mixed with decodes. Read more: 23.4 Chunked prefill (mixed prefill + decode batches) - Speculative decoding: drafting several tokens cheaply and verifying them with one target forward pass, keeping the longest acceptable prefix. Read more: 23.9 Speculative decoding in the engine
- usage ledger: the durable per-request record of tenant, key, model, status, tokens, and latency. Read more: 25.5 The usage ledger and admin API
- Helm chart: a directory of templated Kubernetes YAML plus default values; installing it creates a release. Read more: 1.7 Containers and Kubernetes: images, layers, Pods, Deployments, Services, Helm, kind in Programming and Algorithms
- Service Level Objective (SLO): a target for a defined measure of service behavior over a specified window. Read more: Chapter 13: Engineering Acronyms in Software Engineering
- Design review: a reader who did not write the document checking it against a rubric and returning comments and a decision. Read more: 1.1 Design review: the tracer and the serving platform in Systems Engineering
- Error budget: the per-output bound a quantized layer must stay within. Read more: 21.5 Quantization: int8, int4 groups, fp8, and the KV cache
- model runner: the component that loads a checkpoint and runs one batched forward step, writing K and V into the pool and returning last-token logits. Read more: 23.2 Candle model runner (Llama + bigram, int4), Rust KV cache, sampler and PCG32
- KV cache: per-layer storage of past keys and values, so each decode step processes only the new token. Read more: 21.2 The KV cache, incremental decoding, and generate
- PCG32: an LCG whose output is a permutation (xorshift, then a state-chosen rotation) of the old state. Read more: 12.3 Modular arithmetic, hashing, and PCG32 in Python in Mathematics
- Decode step: a forward pass over one new token against the cache. Read more: 21.2 The KV cache, incremental decoding, and generate
- token budget: the maximum number of tokens, prompt and generated, the scheduler puts into one step. Read more: 20.6 Inside an Inference Engine: How vLLM and SGLang Run a Model
- Prefix cache: a map from token prefixes of past prompts to the KV blocks already computed for them. Read more: 21.4 A radix prefix cache
- Server-Sent Events (SSE): a
text/event-streambody ofdata: ...events, each terminated by a blank line. Read more: 23.1 Your first endpoint: a std-only Rust HTTP/1.1 + SSE server - OpenTelemetry (OTel): the vendor-neutral standard for traces, metrics, and logs, made of an SDK, a collector, and exporters. Read more: Chapter 11: Observability in Systems Engineering
- Log-linear histogram: a histogram with 128 equal buckets per power of two, giving at most 1/128 relative error in fixed memory. Read more: 23.11 An open-loop load generator
- Regression gate: a check that fails a head run only when it is worse than the base by more than a budget and the difference is unlikely under noise. Read more: 23.12 Run comparison and the regression gate
- composition root: the one place (here
main) where independent components are constructed and wired together. Read more: 25.2 The server skeleton - graceful shutdown: stop accepting, let in-flight work finish within a bound, then exit 0. Read more: 1.9 Async Rust and tokio: futures, tasks, channels, cancellation, hyper in Programming and Algorithms
- API key: a credential
tl_<id>_<secret>whose public id locates a record and whose secret proves possession. Read more: 10.1 API Keys, Scopes, Model Allowlists, and Tenants in Software Engineering - Model allowlist: a per-key list of models it may use; empty means all. Read more: 10.1 API Keys, Scopes, Model Allowlists, and Tenants in Software Engineering
- RPM / TPM: requests per minute and tokens per minute, the two per-key budgets. Read more: 10.2 Rate Limiting: RPM Token Buckets and TPM Reserve/Settle in Software Engineering
- Token bucket: a counter capped at that refills at per minute and admits a request when it holds the request’s cost. Read more: 10.2 Rate Limiting: RPM Token Buckets and TPM Reserve/Settle in Software Engineering
- Bounded loads: a cap of per node, with over-cap keys walking clockwise to the next node below it. Read more: 15.9 A consistent hash ring with bounded loads in Programming and Algorithms
- LRU (least recently used): an eviction policy that reclaims the element whose last use is oldest. Read more: 15.3 An intrusive list and an LRU in Programming and Algorithms
- Singleflight: coalescing concurrent misses for one key so a single leader goes upstream and the others wait for its result. Read more: 6.1 Response cache: LRU, TTL, singleflight, and tenant-scoped keys in Systems Engineering
- write-ahead logging (WAL): a journal mode in which commits append pages to a log, so readers and the single writer do not block each other. Read more: 1.11 SQL and SQLite: schema, transactions, WAL mode, indexes, aggregates in Programming and Algorithms
- Contract test: a test of the agreement between two services that runs neither against the other. Read more: 3.6 Contract tests: consumer-driven tests for gateway to engine in Software Engineering
The last part of the pass deploys the platform on kind with per-role Helm charts and a Tilt dev loop, adds Prometheus, Tempo, and Grafana with SLOs and burn-rate alerts, and rehearses a decode worker dying mid-stream. It closes with a code review and a design review of everything built so far.
Learning objectives
- Explain how continuous batching, chunked prefill, and the block manager let many streams share one model.
- Explain why prefill and decode are disaggregated and how the KV transfer between them stays leak-free.
- Explain how the gateway authenticates, limits, routes, caches, and meters requests without the engine knowing about tenants.
- Explain how the SLOs, burn-rate alerts, traces, and dashboards explain a violation.
- Diagnose a decode worker dying mid-stream and keep the system within its error budget.
Before you begin
Section titled “Before you begin”This pass needs Pass 6, whose Python inference stack defines the correct output the engine must reproduce.
In this pass
Section titled “In this pass”The pass builds the engine first, then the gateway, then the deployment and its observability:
- Candle model runner (Llama + bigram, int4), Rust KV cache, sampler and PCG32. Afterwards you can explain how the candle model runner runs Llama and the bigram (int4 included), and how the Rust KV cache and PCG32 sampler match Python.
- Continuous batching scheduler with priority and preemption. Afterwards you can explain how continuous batching admits, prioritizes, and preempts sequences each step.
- Chunked prefill (mixed prefill + decode batches). Afterwards you can explain how chunked prefill mixes prefill chunks with decode steps under a token budget.
- Block manager with prefix cache (none, hash, radix). Afterwards you can explain how the block manager allocates KV blocks and how the none, hash, and radix prefix caches reuse them.
- Async Rust and tokio: futures, tasks, channels, cancellation, hyper. Afterwards you can explain how futures, tasks, channels, and cancellation work in tokio and how hyper serves a request.
- Speculative decoding in the engine. Afterwards you can explain how the engine runs speculative decoding and verifies drafts in one batched step.
- tl-serve: OpenAI-compatible HTTP + SSE on tokio/hyper. Afterwards you can trace how tl-serve parses an OpenAI-compatible request and streams SSE on tokio and hyper.
- Protocol Buffers and gRPC: schema evolution, unary and streaming RPCs, stubs. Afterwards you can explain how Protobuf schemas evolve compatibly and how unary and streaming gRPC calls are made.
- Disaggregated prefill and decode. Afterwards you can explain how disaggregated prefill and decode transfer the KV cache and how the heartbeat client reports health.
- Serving metrics and tracing. Afterwards you can explain how the serving metrics, SLO histograms, and OTel spans are recorded and propagated.
- Tool calls and constrained decoding. Afterwards you can explain how tool calls are parsed and how constrained JSON decoding guarantees valid arguments in the engine.
- An open-loop load generator. Afterwards you can explain why the load generator is open-loop, how its log-linear histogram records latency, and how the Go PCG32 port matches.
- Run comparison and the regression gate. Afterwards you can explain how two runs are compared and when the regression gate fails.
- The server skeleton. Afterwards you can explain how the gateway’s composition root wires its parts from go/config and how graceful shutdown drains requests.
- API Keys, Scopes, Model Allowlists, and Tenants. Afterwards you can explain how API keys authenticate a request and how scopes, the model allowlist, and tenants authorize it.
- Rate Limiting: RPM Token Buckets and TPM Reserve/Settle. Afterwards you can explain how the RPM token bucket and the TPM reserve-and-settle limit traffic.
- SSE streaming proxy. Afterwards you can explain how the SSE streaming proxy forwards events, handles disconnects, and how it upgrades the tracer gateway.
- A consistent hash ring with bounded loads. Afterwards you can explain how a consistent hash ring with bounded loads places keys and caps each node’s share.
- Routing, cascades, and failover. Afterwards you can explain how the worker registry routes requests, how cascades and failover work, and how disaggregated requests are orchestrated.
- Response cache: LRU, TTL, singleflight, and tenant-scoped keys. Afterwards you can explain how the response cache combines LRU and TTL, why singleflight collapses duplicate misses, and why keys are tenant-scoped.
- SQL and SQLite: schema, transactions, WAL mode, indexes, aggregates. Afterwards you can explain how SQLite transactions, WAL mode, and indexes behave and how an aggregate query is written.
- The usage ledger and admin API. Afterwards you can explain how the usage ledger meters requests and how the admin API reads it.
- Contract tests: consumer-driven tests for gateway to engine. Afterwards you can explain how a consumer-driven contract test pins the gateway-to-engine interface.
- Dockerfiles for the gateway and the engine. Afterwards you can explain how the multi-stage Dockerfiles build small gateway and engine images.
- kind cluster, local registry, and port mappings. Afterwards you can explain how the kind cluster, local registry, and port mappings fit together.
- Helm charts and the observability stack. Afterwards you can explain how the Helm charts deploy the gateway, the engine, and the observability stack.
- The Tilt dev loop. Afterwards you can explain how the Tilt dev loop rebuilds and redeploys on change.
- CI for the learner repo. Afterwards you can explain what the repository’s CI runs and in what order.
- Tracing for the serving path. Afterwards you can trace the spans along the serving path and how their context propagates.
- Metrics and log correlation. Afterwards you can explain how metrics and logs are correlated with traces.
- SLOs and multi-window burn-rate alerts. Afterwards you can explain how SLOs set error budgets and why multi-window burn-rate alerts fire when they do.
- Dashboards as code for the serving path. Afterwards you can explain how the dashboards are defined as code for the serving path.
- A decode worker dies mid-stream. Afterwards you can diagnose a decode worker dying mid-stream from its symptoms, explain the fix, and explain how recurrence is prevented.
- Code review: review a seeded PR against your system. Afterwards you can identify the defects in the seeded PR and explain why each matters.
- Design review: the tracer and the serving platform. Afterwards you can explain the design decisions of the tracer and serving platform and the tradeoffs a design review raises.
- What the System Does After Pass 7. Afterwards you can explain how the engine, the gateway, and observability work together on kind to hold the SLOs.
The stages are also in this pass’s manifest, path.tsv. Pass 8 turns to the long-running jobs behind the platform: corpus builds and training runs.
Stages
Section titled “Stages”Generated from path.tsv.
| Stage | Read | Done when |
|---|---|---|
| 1 | Candle model runner (Llama + bigram, int4), Rust KV cache, sampler and PCG32 23.2 Candle model runner (Llama + bigram, int4), Rust KV cache, sampler and PCG32 | You can explain how the candle model runner runs Llama and the bigram (int4 included), and how the Rust KV cache and PCG32 sampler match Python (L10.1). |
| 2 | Continuous batching scheduler with priority and preemption 23.3 Continuous batching scheduler with priority and preemption | You can explain how continuous batching admits, prioritizes, and preempts sequences each step (L10.2). |
| 3 | Chunked prefill (mixed prefill + decode batches) 23.4 Chunked prefill (mixed prefill + decode batches) | You can explain how chunked prefill mixes prefill chunks with decode steps under a token budget (L10.3). |
| 4 | Block manager with prefix cache (none, hash, radix) 23.5 Block manager with prefix cache (none, hash, radix) | You can explain how the block manager allocates KV blocks and how the none, hash, and radix prefix caches reuse them (L10.4). |
| 5 | Async Rust and tokio: futures, tasks, channels, cancellation, hyper 1.9 Async Rust and tokio: futures, tasks, channels, cancellation, hyper | You can explain how futures, tasks, channels, and cancellation work in tokio and how hyper serves a request (lang.09). |
| 6 | Speculative decoding in the engine 23.9 Speculative decoding in the engine | You can explain how the engine runs speculative decoding and verifies drafts in one batched step (L10.8). |
| 7 | tl-serve: OpenAI-compatible HTTP + SSE on tokio/hyper 23.6 tl-serve: OpenAI-compatible HTTP + SSE on tokio/hyper | You can trace how tl-serve parses an OpenAI-compatible request and streams SSE on tokio and hyper (L10.5). |
| 8 | Protocol Buffers and gRPC: schema evolution, unary and streaming RPCs, stubs 1.10 Protocol Buffers and gRPC: schema evolution, unary and streaming RPCs, stubs | You can explain how Protobuf schemas evolve compatibly and how unary and streaming gRPC calls are made (lang.10). |
| 9 | Disaggregated prefill/decode, KV transfer, heartbeat client 23.7 Disaggregated prefill and decode | You can explain how disaggregated prefill and decode transfer the KV cache and how the heartbeat client reports health (L10.6). |
| 10 | Serving metrics, SLO histograms, OTel spans and propagation 23.8 Serving metrics and tracing | You can explain how the serving metrics, SLO histograms, and OTel spans are recorded and propagated (L10.7). |
| 11 | Tool calls and constrained JSON decoding in the engine 23.10 Tool calls and constrained decoding | You can explain how tool calls are parsed and how constrained JSON decoding guarantees valid arguments in the engine (L10.9). |
| 12 | Open-loop load generator, log-linear histogram, Go PCG32 port 23.11 An open-loop load generator | You can explain why the load generator is open-loop, how its log-linear histogram records latency, and how the Go PCG32 port matches (load.01). |
| 13 | Run comparison and regression gate 23.12 Run comparison and the regression gate | You can explain how two runs are compared and when the regression gate fails (load.02). |
| 14 | Server skeleton, composition root, go/config, graceful shutdown 25.2 The server skeleton | You can explain how the gateway’s composition root wires its parts from go/config and how graceful shutdown drains requests (gw.01). |
| 15 | AuthN (API keys) and AuthZ (scopes, model allowlist, tenants) 10.1 API Keys, Scopes, Model Allowlists, and Tenants | You can explain how API keys authenticate a request and how scopes, the model allowlist, and tenants authorize it (gw.02). |
| 16 | Rate limiting: RPM token bucket + TPM reserve/settle 10.2 Rate Limiting: RPM Token Buckets and TPM Reserve/Settle | You can explain how the RPM token bucket and the TPM reserve-and-settle limit traffic (gw.03). |
| 17 | SSE streaming proxy (upgrades gw.00) 25.3 The SSE streaming proxy | You can explain how the SSE streaming proxy forwards events, handles disconnects, and upgrades gw.00 (gw.04). |
| 18 | Consistent hash ring with bounded loads 15.9 A consistent hash ring with bounded loads | You can explain how a consistent hash ring with bounded loads places keys and caps each node’s share (ds.09). |
| 19 | Worker registry, routing, cascades, failover, disaggregated orchestration 25.4 Routing, cascades, and failover | You can explain how the worker registry routes requests, how cascades and failover work, and how disaggregated requests are orchestrated (gw.05). |
| 20 | Response cache: LRU + TTL, singleflight, tenant-scoped keys 6.1 Response cache: LRU, TTL, singleflight, and tenant-scoped keys | You can explain how the response cache combines LRU and TTL, why singleflight collapses duplicate misses, and why keys are tenant-scoped (gw.06). |
| 21 | SQL and SQLite: schema, transactions, WAL mode, indexes, aggregates 1.11 SQL and SQLite: schema, transactions, WAL mode, indexes, aggregates | You can explain how SQLite transactions, WAL mode, and indexes behave and how an aggregate query is written (lang.11). |
| 22 | Usage ledger, metering, admin API 25.5 The usage ledger and admin API | You can explain how the usage ledger meters requests and how the admin API reads it (gw.07). |
| 23 | Contract tests (R6): consumer-driven tests for gateway to engine 3.6 Contract tests: consumer-driven tests for gateway to engine | You can explain how a consumer-driven contract test pins the gateway-to-engine interface (craft.20). |
| 24 | Dockerfiles for the gateway and the engine 10.2 Dockerfiles for the gateway and the engine | You can explain how the multi-stage Dockerfiles build small gateway and engine images (dep.01). |
| 25 | kind cluster + local registry + port mappings 10.3 kind cluster, local registry, and port mappings | You can explain how the kind cluster, local registry, and port mappings fit together (dep.02). |
| 26 | Helm charts for the gateway and the engine, plus the observability stack 10.4 Helm charts and the observability stack | You can explain how the Helm charts deploy the gateway, the engine, and the observability stack (dep.03). |
| 27 | Tilt dev loop 10.5 The Tilt dev loop | You can explain how the Tilt dev loop rebuilds and redeploys on change (dep.04). |
| 28 | CI for the learner repo 10.6 CI for the platform repo | You can explain what the repository’s CI runs and in what order (dep.05). |
| 29 | Tracing for the serving path 11.2 Tracing for the serving path | You can trace the spans along the serving path and how their context propagates (obs.01). |
| 30 | Metrics and log correlation 11.3 Metrics and log correlation | You can explain how metrics and logs are correlated with traces (obs.02). |
| 31 | SLOs and multi-window burn-rate alerts 11.4 SLOs and multi-window burn-rate alerts | You can explain how SLOs set error budgets and why multi-window burn-rate alerts fire when they do (obs.03). |
| 32 | Dashboards as code for the serving path 11.5 Dashboards as code for the serving path | You can explain how the dashboards are defined as code for the serving path (obs.04). |
| 33 | A decode worker dies mid-stream 12.2 A decode worker dies mid-stream | You can diagnose a decode worker dying mid-stream from its symptoms, explain the fix, and explain how recurrence is prevented (ops.01). |
| 34 | Code review: review a seeded PR against your system 6.2 Code review | You can identify the defects in the seeded PR and explain why each matters (craft.08). |
| 35 | Design review: tracer and serving platform 1.1 Design review: the tracer and the serving platform | You can explain the design decisions of the tracer and serving platform and the tradeoffs a design review raises (review.01). |
| 36 | What the system does after Pass 7 B.9.1 What the System Does After Pass 7 | You can explain how the engine, the gateway, and observability work together on kind to hold the SLOs. |