Skip to main content
← PROBLEMS / ARCHITECTURE
An end-to-end domain learning journey

Design a 15,000 RPS Semantic &
Prompt Caching Tier for Foundation Models.

Combine <1 ms L1 Radix prefix hashing with 12 ONNX INT8 embedding workers, 8-shard SQ8 HNSW (110.7 GB DRAM), Zstd NVMe RocksDB (400 GB), and O(1) model-epoch invalidation.
Start the journey5 stages· Last modified Nov 26, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When designing a multi-tenant semantic cache, enforce tenant pre-filtering, entity/negation guards, and fail-open timeouts under 15 ms.

TL;DR30-second simplified summary
▾

100M 384-d SQ8 vectors fit in 110.7 GB DRAM (RF=2) with 400 GB Zstd RocksDB on NVMe. Async Kafka write-back keeps streaming TTFT unblocked.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Dual-Tier Radix Prefix & HNSW Semantic Caching
Understand how L1 exact prefix tries complement L2 SQ8 HNSW semantic vector search.
Little's Law & Tail Latency Budgets
Know how to size ONNX embedding worker pools and enforce fail-open circuit breakers.
Full walkthrough · 5 stages
01
L4 · FUNDAMENTALS

R & E · Requirements, Scale Targets & 100M Entry Sizing.

Targets: 5,000 RPS sustained, 15,000 RPS peak, >25% combined hit ratio, <15 ms p99 evaluation overhead, 100M active entries.

Sizing 100M 384-d SQ8 vectors = 38.4 GB + 14.4 GB HNSW edges (M=16) + 2.56 GB L1 Radix = 55.36 GB × 2 (RF=2) = 110.7 GB DRAM across 8 shards. Zstd-compressed payloads (2 KB avg) = 400 GB NVMe.

CAPACITY PHYSICS

FP32 Unsharded vs. SQ8 Sharded DRAM + NVMe RocksDB

Before · Naive FP32 All-In-RAM
  • 153.6 GB raw vectors alone
  • 400+ GB uncompressed JSON in RAM
  • High GC pauses
After · SQ8 HNSW + Zstd NVMe RocksDB
  • 110.7 GB total DRAM (RF=2)
  • 400 GB Zstd NVMe payloads
  • <15 ms p99 evaluation
02
L4 · FUNDAMENTALS

S & H · Storage Entities & 5-Tier Decoupled Architecture.

Edge Gateway normalizes prompts and derives tenant_hash = HMAC-SHA256(master_key, tenant_id). L1 Radix Trie checks exact matches and emits GPU KV-cache pod affinity hints.

L2 queries sharded SQ8 HNSW with a Roaring Bitmap tenant pre-filter, then fetches the Zstd payload from NVMe RocksDB.

5-TIER PIPELINE

End-to-End Semantic & Prompt Caching Topology

Edge Normalizer15K RPS + HMAC TenantL1 Radix Trie<1 ms Exact / KV HintONNX + SQ8 HNSW<10 ms ANN (tau=0.08)LLM Origin + KafkaStream + Async CommitNormalizedL1 MissL2 Miss / Fail-Open
03
L5 · APPLIED DESIGN

A & D · RPC Contracts, Cosine Calibration & Slot Guard.

EvaluateCache accepts (tenant_id, model_id, model_epoch, system_prompt_hash, user_prompt, max_cosine_dist, deadline_ms) and returns hit_tier + cached_payload + kv_prefix_affinity.

Cosine distance calibration divides space into Safe (d < 0.08), Gray (0.08 <= d < 0.14), and Reject (d >= 0.14). An Entity/Negation Slot Guard enforces exact parity on numbers, dates, and negations.

REQUEST SEQUENCE

Sub-15ms Evaluation & Fail-Open Origin Fallback

GatewayL1 RadixL2 HNSWLLM Origin1. Prefix Check (<1 ms)2. Embed + HNSW (10 ms)3. Miss or >12 ms Breaker
04
L5 · APPLIED DESIGN

E · Technology Trade-Offs, Dynamic TTL & Epoch Invalidation.

HNSW SQ8 delivers 96.5% Recall@10 in 5.5 ms p99; DiskANN takes 18–25 ms on NVMe (violating SLA) and IVF-PQ distorts cosine distances near tau = 0.08.

Volatility-aware TTL assigns 7d to static docs, 1h to RAG knowledge, and 0s bypass to live data. Bumping model_epoch invalidates stale entries in O(1) without cluster-wide flushes.

3-3-3 EVALUATION

L2 Vector Index Engine Trade-Offs (100M 384-d)

05
L6 · SCALE & TRADE-OFFS

D · Failure Modes, Circuit Breakers, Assumptions & Glossary.

Three circuit breakers govern safety: Latency Breaker (>12 ms p99 opens L2 bypass), Drift Breaker (5% shadow LLM Judge drift >1.5% tightens tau from 0.08 to 0.05), and Queue Shedding (worker depth >64).

Assumptions & Limitations: Assumes low-temperature (T <= 0.3) workloads and canonicalizable prompts; high-entropy creative generation or strict real-time feeds must set bypass_cache = true.

CIRCUIT BREAKER

Fail-Open Cache Resilience State Machine

Drift > 1.5%p99 > 12 ms5% probe < 8 msCLOSED (L1 + L2Active)DEGRADED(tau=0.05)OPEN (L2 Bypass ->Origin)
Decision Exercise · Make the Call

A deployment upgrades Llama-3.3-70B weights from v4.1 to v4.2 during peak 15,000 RPS traffic. How do you invalidate stale cached responses without crashing the GPU cluster?

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 4
Score: 0/4

Why does the design use Roaring Bitmap pre-filtering in HNSW instead of post-filtering top-K results by tenant_id?

Recommended Learning Flow