PART 2 · PRODUCTION SYSTEMS · S3

Edge Caching, APQ & Surrogate-Key Invalidation

Shift federated GraphQL reads from origin POST requests to globally cached CDN GET POPs using SHA-256 Automatic Persisted Queries, strictest-wins @cacheControl bubbling, and sub-second entity-level surrogate-key purges.

Act I · Scale Math & Caching Physics

Edge Offload, Bubbling Rules & Sub-Second Purge Envelope

Act 1 of 5
Edge Cache Offload
82% – 94%

APQ GET requests terminated directly at CDN POPs without waking the Router or subgraph pods.

Edge p95 vs Origin p95
18 ms vs 145 ms

Eliminating cross-region router planning and parallel subgraph fan-out slashes read tail latency by 8×.

Strictest-Wins Bubbling
min(maxAge) + PRIVATE

Federated @cacheControl reducer takes the lowest TTL across all queried subgraphs; any PRIVATE field overrides PUBLIC.

Global Surrogate Purge
< 150 ms

Entity-level CDN invalidation via CDC or mutation hooks soft-purges Product:p_42 across all edge POPs.

Act II · Wire & Policy Contracts

APQ GET Handshake & Federated @cacheControl Policy

Act 2 of 5
APQ GET Handshake & Surrogate-Key Response Headers
Subgraph @cacheControl SDL & Router Cache Policy (YAML)
Act III · Interactive 6-Node Edge Cache, APQ & Surrogate-Key Simulator

CDN POP Lookup, @cacheControl Bubbling & Chaos Switchboard

EDGE HIT · 91% OFFLOAD
Transport:
Query Scope:
Invalidation:
Edge Hit Ratio 91.4% 18 ms edge p95
Emitted Cache-Control public, max-age=60, swr=30 min(300, 60) + PUBLIC
Origin Subgraph RPS 3,440 RPS Out of 40,000 total edge RPS
Freshness & Security FRESH · ISOLATED Surrogate soft-purge < 150 ms
Edge Caching Pipeline · APQ GET & CDN Lookup
PHASE 1 · APQ GET
Edge CDN POP Global HTTP Cache + Surrogate-Key Store
Live @cacheControl Bubbling & Surrogate-Key Reducer min(maxAge) + Strictest Scope
Chaos Switchboard
0 Active
Live Edge & Purge Console
Act IV · Auto-Synced Zero-Dependency TypeScript Blueprints

APQ Handshake, @cacheControl Reducer & Surrogate Purge Worker

Live-Injected Simulator Params
Act V · Production Stack Mapping, Architectural Tradeoffs & SLOs

Production Ecosystem, Caching Tradeoffs & SLO Envelope

Act 5 of 5
Production Stack Mapping
6 Edge Caching & Purge Layers
Layer / Primitive Production Tools Operational Role
Edge CDN Layer Fastly / Cloudflare Enterprise Terminates APQ GET traffic at global POPs, honors stale-while-revalidate, and executes instant Surrogate-Key purges.
APQ & Safelist Registry Apollo Router / Persisted Queries (PQ) Resolves SHA-256 query hashes from build-time safelists or Redis APQ, rejecting arbitrary queries in strict mode.
GraphQL-Aware Edge Proxy Stellate / GraphQL Hive Edge Parses GraphQL responses at the edge to auto-tag entity keys (Product:p_42) and scope partial invalidations.
Entity Cache Store Redis Cluster (L2 Router Entity Cache) Caches shared subgraph _entities sub-responses even when the outer query includes a PRIVATE Cart field.
Change-Data-Capture Purge Bus Debezium + Kafka → CDN Purge API Streams database commits into debounced entity-key soft-purges so updates propagate globally in < 150 ms.
Telemetry & Cache Analytics OpenTelemetry + Fastly Real-Time Logs Tracks per-operation hit ratios, SWR revalidation rates, and alerts immediately on PRIVATE cache violations.
Tradeoff 01 Query Persistence

Dynamic APQ vs. Build-Time Safelists (PQ)

Build-Time Safelist

Zero PersistedQueryNotFound 2-RTT penalties, immune to Redis flushes, and blocks arbitrary malicious queries at the edge.

Dynamic APQ

Zero CI build step required—clients register hashes on first miss—but vulnerable to Redis eviction storms and arbitrary query registration.

Verdict Use Build-Time Persisted Query Safelists for first-party web/mobile apps; reserve dynamic APQ for trusted internal tooling.
Tradeoff 02 Cache Placement

Edge HTTP Cache vs. Router Entity Cache

Edge HTTP + Router Entity Cache

Edge POPs absorb 90%+ of public reads in 18 ms; Router L2 entity cache still caches Product even on PRIVATE Cart queries.

Edge HTTP Only

Any single PRIVATE field forces private, no-store on the whole response, dropping hit rate to 0% for logged-in users.

Verdict Split Public Catalog queries for Edge CDN caching and pair with a Router Redis Entity Cache for personalized views.
Tradeoff 03 Purge Semantics

Hard Purge vs. Soft Purge + SWR

Soft Purge + SWR

Marks the edge object stale so clients still get an 18 ms response while one singleflight request refreshes origin in the background.

Hard Purge

Deletes cached bytes immediately—guarantees strict read-after-write, but hot-key purges send a thundering herd straight to origin.

Verdict Default to Soft Purge + stale-while-revalidate with request coalescing; reserve Hard Purge for legal/compliance takedowns.
Tradeoff 04 Tag Granularity

Granular Entity Keys vs. Broad Type Keys

Granular (Product:p_42)

Invalidates only responses referencing p_42, keeping 99.9% of the catalog cache warm and origin RPS flat.

Broad (Product:*)

Simple to emit, but a single price edit wipes 40K+ unrelated cached pages and triggers a massive origin purge stampede.

Verdict Always tag responses with granular Type:ID surrogate keys (and cap header size via key hashing for large lists).
Production Edge Caching SLOs
Target Reliability & Security Envelope
Public Edge Offload ≥ 88% APQ GET / Safelist POP hits
Edge Read p95 < 25 ms Global CDN + SWR
Surrogate Purge SLA < 150 ms Entity-key soft-purge
Private Cache Leaks 0.00% Strict PRIVATE bubbling