Single-shard tenant HNSW + cross-encoder gating hits < 15 ms, while 1.25x bounded-load prefix hashing preserves 85%+ L3 KV locality.
TL;DR30-second simplified summary▾
The gateway derives an rbac_scope_hash, probes L1 SHA-256 (< 1 ms) and L2 tenant-sharded HNSW + INT8 cross-encoder (~12 ms) behind a 20 ms fail-open breaker.
Misses route via 1.25x bounded-load consistent hashing over the first 512 tokens to warm vLLM/SGLang RadixAttention workers.
Stage 1: 100K QPS Traffic Profile & Hit-Rate Economics.
Why this matters: Quantify GPU savings, latency budgets (< 15 ms hit, < 180 ms miss TTFT), and hit-rate targets across L1, L2, and L3.
Assume 100K QPS with 15% exact repeats (L1), 25% semantic paraphrases (L2), and 60% novel queries sharing 4K-token system/RAG prefixes (L3). Offloading 40% of total traffic at L1/L2 cuts GPU fleet size by 40%, while L3 prefix KV reuse cuts prefill FLOPs on the remaining 60% by 80%.
40% Total LLM Bypass (L1+L2) + 80% Prefill Savings (L3)
1.40K QPS GPU Offload: Serving 40% of queries from L1/L2 saves dozens of GPU inference pods at peak.
2.15 ms Hit SLO: L1 (< 1 ms) + L2 (4 ms embed + 3 ms HNSW + 5 ms cross-encoder) stays safely under 15 ms.
L1 and L2 absorb 40% of 100K QPS in < 15 ms while L3 prefix KV reuse accelerates the remaining 60% on GPUs.
Stage 2: Capacity Sizing for Redis/Valkey L1/L2 & KV Pools.
Why this matters: Size DRAM for 100M cached prompt-response pairs, 384-D HNSW graphs, and offloaded DRAM KV blocks.
Storing 100M cached entries (average 2 KB response + 384-D SQ8 vector = 2.4 KB/entry) requires ~240 GB data + ~45 GB HNSW graph overhead = ~285 GB RAM (easily sharded across a 16-node Redis/Valkey cluster with 32 GB/node + RF=2). Meanwhile, each GPU host allocates 256 GB host DRAM as an L3 KV offload tier.
285 GB Sharded L1/L2 Cache + Per-Node DRAM KV Offload
1.Tenant-Keyed Sharding: Sharding L2 HNSW by tenant_id keeps every lookup to a single Redis shard (zero scatter-gather across 16 nodes).
2.SQ8 Vector Savings: Quantizing 384-D FP32 vectors to SQ8 cuts vector RAM 4x from 153 GB to 38.4 GB.
Sharding 100M SQ8 HNSW entries by tenant_id fits in a 16-node Redis/Valkey cluster with single-shard lookup latency.
Stage 3: Tenant/RBAC Namespace Filtering & Security.
Why this matters: Guarantee zero cross-tenant or cross-permission cache leaks in multi-tenant RAG deployments.
In enterprise RAG, two users in the same org may have different document ACLs. The API Gateway computes an rbac_scope_hash from the caller's tenant_id and role/ACL group IDs and enforces it as a mandatory pre-filter on L1 keys, L2 HNSW searches, and L3 KV prefix sharing—preventing unauthorized context leakage.
Mandatory RBAC Namespace Scoping Across L1, L2 & L3
1.Zero Cross-ACL Hits: Users with different ACL groups never share L1/L2 RAG responses or private document KV prefixes.
2.Shared Public Base: Global non-sensitive system instructions can still share a common public prefix namespace.
Deriving an rbac_scope_hash at the gateway enforces strict tenant and ACL isolation across every cache tier.
Stage 4: Embedding + HNSW + Cross-Encoder Pipeline.
Why this matters: Execute the 12 ms L2 semantic lookup pipeline with bounded tail latency and circuit-breaker bypass.
At 100K QPS, an ONNX Runtime pool (Triton/ORT) batches incoming misses every 1 ms to embed queries in ~4 ms, queries the tenant's Redis/Valkey HNSW shard (~3 ms), and runs a quantized INT8 TinyBERT cross-encoder on Top-1 matches (~5 ms). If L2 latency exceeds 20 ms, a circuit breaker bypasses L2 straight to L3 GPU inference.
12 ms L2 Semantic Pipeline with 20 ms Circuit Breaker
1.INT8 Cross-Encoder: Quantizing the cross-encoder to INT8 cuts pair-verification latency to ~5 ms on CPU/L4 GPUs.
2.Fail-Open Bypass: Caches are pure accelerators; if Redis or ONNX degrades, traffic fails open cleanly to GPU inference.
Micro-batched ONNX embeddings, single-shard HNSW, INT8 cross-encoder gating, and a 20 ms circuit breaker keep L2 fast and safe.
Stage 5: Bounded-Load Prefix Consistent Hash Router.
Why this matters: Route 60K QPS of cache misses to warm vLLM/SGLang RadixAttention workers without hot-spotting.
The miss router hashes the first 512 tokens of the prompt onto a consistent hash ring with virtual nodes (150 vnodes/GPU replica) to maximize L3 KV prefix hits. To protect against viral tenant prompts, if the primary replica's active KV/queue load exceeds 1.25x cluster average, the router walks clockwise to the next replica.
Consistent Hash Ring + 1.25x Bounded-Load Spillover
1.Graceful Autoscaling: Consistent hashing minimizes KV cache thrashing when GPU replicas scale up or down.
2.Dual-Warm Replicas: High-traffic prefixes naturally warm 2-3 adjacent ring replicas during peak bursts.
Virtual-node consistent hashing with 1.25x bounded-load spillover preserves L3 KV locality while preventing GPU hot spots.
Stage 6: HBM-to-DRAM KV Offloading & Async Write-Back.
Why this matters: Expand L3 KV prefix retention 10x via DRAM offloading and keep L1/L2 write-back off the critical path.
GPU HBM is scarce (80-192 GB), so active conversations can evict shared RAG KV blocks prematurely. Offloading evicted RadixAttention blocks asynchronously to 256 GB host DRAM (and restoring via pinned PCIe DMA in ~2 ms) keeps prefix hit rates high, while completed responses publish to Kafka for async L1/L2 indexing.
Pinned PCIe KV Offload & Asynchronous L1/L2 Write-Back
1.2 ms DMA vs 150 ms Prefill: Restoring 64 MB of KV blocks over PCIe Gen5 takes ~2 ms—75x faster than recomputing prefill.
2.Zero User Latency: Async Kafka write-back decouples HNSW insertion from the user's streaming response.
DRAM KV offloading restores cold prefix blocks in ~2 ms over PCIe, while Kafka async write-back keeps L1/L2 updates zero-latency.
Stage 7: Epoch Invalidation, Canary Thresholds & Observability.
Why this matters: Prevent stale answers on model/KB updates and tune cosine/cross-encoder thresholds safely in production.
Attach (model_epoch, kb_version, ttl_sec) to every cache key/metadata record so rolling a new model or re-indexing RAG documents invalidates stale entries in O(1). Track l1_hit_rate, l2_hit_rate, l2_false_positive_audit_rate, and l3_prefix_reuse_pct, running shadow evaluations on 1% of L2 hits against the live LLM.
O(1) Epoch Invalidation & 1% Shadow False-Positive Auditing
1.1% Shadow Verification: Asynchronously running 1% of L2 hits against the live LLM measures real false-positive rates without affecting user latency.
2.Domain-Specific Thresholds: Medical/financial tenants use stricter thresholds (CE >= 0.95) than FAQ support bots (CE >= 0.88).
Epoch invalidation, 1% shadow LLM auditing, and per-domain threshold tuning keep semantic caches accurate over time.
Practice: Make the trade-off yourself.
Why should L2 HNSW indexes be sharded by `tenant_id` (and pre-filtered by `rbac_scope_hash`) rather than using one global HNSW index?