PART 2 · PRODUCTION SYSTEM · S1

Apollo Router & Distributed Query Execution

How a Rust-based federated router compiles query plans once, coalesces duplicate entity keys across HTTP/2 subgraphs, and isolates tail-latency failures without breaking checkout.

Act I · Scale Math & Capacity Envelope

Production Router Throughput, Caching & Fault Budgets

Act 1 of 5
Single-Node Throughput
120K RPS / Node

Rust Tokio async event loop with zero GC pauses handles massive fan-out concurrency on a single 16-vCPU pod.

Query Plan Compilation
< 0.8 ms vs 32 ms

Warm LRU Query Plan cache hit vs cold AST compilation; single-flight coalescing prevents restart CPU stampedes.

Entity Key Deduplication
3.4× – 12× Reduction

Entity key deduplication ratio via in-flight coalescing collapses duplicate parent references into one compact _entities batch.

Degraded-Mode Availability
99.98% Partial SLO

Nullable subgraph isolation & per-subgraph 250 ms circuit breakers keep core checkout responses alive during optional outages.

Act II · Wire Contracts & Router Pipeline

HTTP/2 Subgraph Wire Envelope & Traffic Shaping Policy

Act 2 of 5
Subgraph HTTP/2 Wire Envelope & _entities Batch
Router Resilience & Traffic Shaping Policy (YAML)
Act III · Interactive Federated Router Simulator & Chaos Switchboard

Query Plan LRU, Entity Coalescing & Subgraph Circuit Breakers

ROUTER HEALTHY · 200 OK
Plan Cache:
Entity Coalescing:
Subgraph Transport:
Router Overhead 0.72 ms SLO < 2.5 ms p99
Subgraph Calls & Keys Sent 4 Calls · 3 Keys 8 raw keys → 3 deduped
Plan Cache Hit Rate 99.4% Single-flight armed
Response Health 200 OK · 100% Data 4 / 4 subgraphs healthy
Federated Topology · Parse & Plan LRU Cache
STEP 1 · PLAN LRU
DRILL ACTIVE
Rust Router Plan LRU + Entity Coalescer
Compiled Query Plan DAG Critical Path: 78 ms
Entity Key Coalescing & Partial Response 2.7× Deduped
Chaos Switchboard
0 Active
Live Router Event Console
Act IV · Zero-Dependency Reference Blueprints

Auto-Synced TypeScript Primitives

Highlights Synced to Simulator
Act V · Production Stack Mapping, Tradeoffs & SLOs

Production Ecosystem, Architecture Tradeoffs & SLO Targets

Act 5 of 5
Production Stack Mapping
6 Core Layers
Role Production Standard Why It Wins
Federated Router Apollo Router (Rust) / WunderGraph Cosmo Native compiled execution with zero GC pauses, sustaining 100K+ RPS/node at sub-2ms overhead.
Schema Registry & Uplinks GraphOS / GraphQL Hive Atomic hot-reloading of composed supergraph artifacts with zero-downtime router rollouts.
Subgraph Transport Tokio + Hyper HTTP/2 Multiplexing Multiplexes hundreds of concurrent _entities calls over persistent TLS sockets without HoL blocking.
Custom Auth / Telemetry Hooks Rhai Scripts / External Coprocessors Injects JWT claim propagation and tenant headers cleanly without recompiling the core router binary.
Distributed Tracing OpenTelemetry + W3C traceparent + FTV1 Correlates per-field resolver spans across every subgraph into a single flamegraph waterfall.
Edge / Plan Caching In-Process LRU + Redis APQ In-memory LRU keeps plan lookups < 0.8 ms while Redis APQ shares persisted query hashes across pods.
Tradeoff 01 Runtime Engine

Rust Router vs. Node.js Gateway

Rust Router (Tokio)

Deterministic p99 (< 2.5 ms), zero stop-the-world V8 GC pauses, and 8×–10× lower pod memory under high fan-out.

Node.js Gateway

Easy inline TypeScript plugins, but JSON serialization and GC spikes degrade tail latency past 5K RPS/pod.

Verdict Run a Rust Router on the hot path and offload custom business middleware to Rhai scripts or out-of-band coprocessors.
Tradeoff 02 Error Isolation

Partial Data vs. Strict Non-Null (!)

Nullable Subgraph Fields

When Reviews times out at 250 ms, reviews: null + errors[] preserves checkout orders & pricing at 200 OK.

Strict Non-Null (!)

Simplifies client types, but a single optional subgraph timeout bubbles null up and wipes the entire root response.

Verdict Keep cross-subgraph edges nullable by default so optional services can fail independently without taking down checkout.
Tradeoff 03 Tail Latency

Hedged Requests vs. Tail-Latency Amplification

Bounded Hedging (p95 Delay)

Firing a second idempotent read after 45 ms slices p99 latency in half when a single subgraph pod hits GC pause.

Unbounded Hedging

During a brownout, blind retries double traffic against already-struggling subgraphs and trigger cascading failure.

Verdict Enable hedging only on idempotent reads and cap total hedge traffic at ≤ 5% via a token-bucket retry budget.
Tradeoff 04 Plan Caching

In-Process LRU vs. Distributed Plan Cache

In-Process LRU + Singleflight

Zero network hop (< 0.8 ms lookup) with single-flight deduplication preventing duplicate cold compiles per pod.

Distributed Redis Plan Cache

Shares compiled plans across newly scaled pods, but adds 1–3 ms Redis serialization overhead to every hot query.

Verdict Use L1 in-process LRU for sub-ms hot hits, optionally backed by an L2 Redis warm-up cache for massive schemas.
Production Router SLOs
Target Reliability Envelope
p99 Router Overhead < 2.5 ms Warm LRU + Tokio HTTP/2
Plan Cache Hit > 99.5% 4,096-entry normalized LRU
Partial Availability 99.99% Nullable subgraph isolation
Subgraph Timeout Budget 250 ms Per-subgraph circuit breaker