Explore cache-aside, stale reads, Bloom filters, request coalescing and cache tiers in seven steps, with calculated means and explicit request paths.
Every open reaches the database
Before exams, students repeatedly open the same guide. In this example, all 1,000 legitimate reads per second reach the database. Measure hotspots and the read/write mix before choosing a cache. Read-heavy traffic is a condition of this case, not a universal 80/20 law.
Key judgment: Identify the bottleneck before introducing a copy that avoids repeated work.
Check the cache, then fetch on a miss
Add a cache-aside layer. The API checks the cache and returns a hit. On a miss, the API queries the database and fills the cache. The lookup animation is slowed down: its 180 ms dwell is not a real cache latency. A miss is normal; the database remains authoritative.
Key judgment: The application owns the origin query. The miss path must remain correct.
Put hit rate into the formula
Assume total mean path times of 1 ms for a hit and 50 ms for a miss. Mean latency is H×1+(1−H)×50: 3.45 ms at 95% hits and 25.5 ms at 50%. With fixed path means, this relationship is linear. It does not predict queuing, overload, network variation or p95.
Key judgment: Weight mutually exclusive total paths; do not count a hop twice.
The database changed; the copy did not
A guide changes from v1 to v2; the illustrative $20→$25 badges make the copies visible. Reading the old cache is a stale read, not a dirty read of an uncommitted transaction. Write-then-invalidate limits the window, but a delayed old query can refill stale data. Version checks or stronger consistency need a separate design.
Key judgment: Invalidation is not proof of strong consistency. Consider the full concurrent timeline.
Do not repeatedly fetch absent keys
A Bloom filter can reject a key definitely absent from its set. A maybe-present result still needs cache and database checks because false positives exist. Extra absent-key probes in the animation are outside the legitimate-read latency formula. Insert new valid keys promptly. The filter is neither authorization nor an exact existence lookup.
Key judgment: Reject a definite negative, verify a positive, and account for filter updates.
Coalesce one hot-key fetch
When one hot key expires, single-flight coalesces overlapping calls for that key within one process: one fetch runs and waiters share its result. Multiple processes need separate coordination; this is not a global database lock. TTL jitter spreads different keys across expiry times, but alone cannot protect one hot key. Bound failures, waits and retries.
Key judgment: Coalescing protects an in-flight same-key batch; jitter spreads different keys. They solve different problems.
L1 and L2 need coordinated invalidation
L1 is process-local; L2 is a shared remote cache. With an 80% L1 hit rate and a 90% conditional L2 hit rate among L1 misses, 2% of legitimate reads reach the origin. Total path means of 0.1, 2 and 50 ms give 1.44 ms. Invalidating L2 does not clear other processes’ L1 copies; use versions, notifications or bounded TTLs.
Key judgment: L2 hit rate is conditional on an L1 miss. Faster local copies add consistency responsibilities.
Caches, Bloom filters and coalescing do not replace authorization. Shared keys need the correct user, tenant or permission context, and L1/L2 invalidation must be coordinated.