Home/Labs/5-Layer Cache Stack Filter
All 280 Labs
INTERACTIVE LAB🏢

Multi-Layer Caching: CDN vs App-Layer vs DB-Layer Lab (Interactive)

Toggle browser, CDN, gateway, Redis, and buffer-pool tiers and cascade live QPS down to physical disk I/O. Build a defense-in-depth caching stack layer by layer and watch surviving traffic multiply-shrink toward the NVMe tier.

5-Layer Defense-in-Depth Cache Stack

Browser → CDN → Gateway → Redis → Buffer Pool → Disk. Cascade real traffic and see what survives to NVMe.

1. Browser / Mobile
IndexedDB, ServiceWorker · serves in 0 ms
2. Edge CDN
Cloudflare / Fastly PoPs · serves in 10 ms
3. API Gateway
NGINX / Envoy micro-cache · serves in 2 ms
4. App In-Memory
Redis Cluster / Memcached · serves in 0.7 ms
5. DB Buffer Pool
InnoDB / Shared Buffers · serves in 0.3 ms
Avg response latency
3.39 ms
traffic-weighted across tiers
Reaching physical disk
338/s
0.34% of total
Total offload
99.66%
intercepted before NVMe I/O
Traffic cascade (what survives each filter)
1. Browser / Mobile
100.0k in40.0k absorbed
2. Edge CDN
60.0k in30.0k absorbed
3. API Gateway
30.0k in7.5k absorbed
4. App In-Memory
22.5k in19.1k absorbed
5. DB Buffer Pool
3.4k in3.0k absorbed
NVMe Disk
338/s30 ms each
Multiplicative filtering
survivors = QPS × Π(1 − hitᵢ) over 5 enabled layers
= 100.0k × (1−40%) × (1−50%) × (1−25%) × (1−85%) × (1−90%) = 338/s to disk
Reddit/YouTube math: even 80% edge hit rates compound — five mediocre layers beat one perfect one, and the buffer pool (layer 5) saves the disk even when Redis misses.

How It Works Under the Hood

High-scale services never trust one cache; they stack five filters: the browser cache (0ms, fingerprinted assets), edge CDN PoPs (5–20ms, public HTML/media), API-gateway micro-cache (1–3ms, 5–60s authenticated spikes), application Redis (0.5–1.5ms, entities and sessions), and the database buffer pool (0.1–0.5ms, raw 8/16KB pages in InnoDB/Postgres RAM). Because survivors multiply — 50% absorbed here, 80% of the rest there — a tiny fraction reaches disk, letting Reddit and YouTube run global traffic on lean database footprints while the buffer pool quietly saves SSD I/O on every Redis miss.

Core Architectural Principles

  • Surviving traffic = QPS × Π(1 − hitᵢ): mediocre per-layer ratios compound into near-total disk protection.
  • Each layer has a distinct job: edge for static/public, gateway for burst micro-caching, Redis for entities, buffer pool for pages.
  • Staleness debugging across five layers requires unified headers, CDC-driven invalidation, and distributed trace IDs.
Interview Round Script

In full-stack designs, walk the request Browser → CDN → Gateway → Redis → Buffer Pool → Disk with per-layer hit assumptions and latency numbers — interviewers score this as systems depth. Explicitly name the database buffer pool: showing you know Postgres itself caches pages in RAM separates seniors from memorizers. Cite Reddit’s Fastly + Redis/Cassandra stack as the reference architecture.

Key Trade-Offs

Compounding layers deliver huge throughput on minimal hardware but make staleness debugging and coordinated invalidation a cross-five-tier problem.

Related Curriculum Chapter

Multi-Layer Caching: CDN vs App-Layer vs DB-Layer

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs