The sticky note, and World Cup match day
In school, Rohan kept the five formulas he used every day on a sticky note on his desk, and walked to the library for everything else. The note was fast because it was small and close. It was risky because when a formula changed, the note was wrong until someone updated it.
Ten years later Rohan runs CricLive, a cricket-score website. On World Cup match days, 20 million people refresh the same few pages, and his database is at 95% CPU by the first over. He needs a sticky note for software, which is a cache. (Rohan, CricLive and every number here are made up for teaching.)
Caching means keeping a small, fast copy of hot data near where it's used, and accepting the job of keeping that copy honest. The two hard problems are the ones the sticky note already shows:
- What to keep: eviction.
- When it's wrong: invalidation.
Match day brings them all, plus the failures that only appear at scale:
| What happens |
Idea it forces |
| "The database is at 95% by the first over" |
Where caches live |
| "Which way do reads and writes go?" |
Cache-aside and the other patterns |
| "The cache is full" |
Eviction |
| "The score page showed a wicket that was overturned" |
Invalidation |
| "The score key expired and the database fell over" |
Stampedes |
| "Bots keep asking for match 999999" |
Penetration and Bloom filters |
| "We restarted Redis and everything broke" |
Avalanches |
| "India vs Pakistan melted one cache node" |
Hot keys |
| "Should we cache ticket stock too?" |
What not to cache, and sizing |
This guide links to Inside a database for what the cache protects, and to Foundations and data for the basics.
1. "The database is at 95%": where caches live
Rohan can keep sticky notes in many places between a fan's phone and his database:
flowchart LR
U@{ icon: "algomi:ext-device", label: "Fan's browser cache", pos: "b", h: 52 }
CDN@{ icon: "algomi:sec-globe", label: "CDN edge", pos: "b", h: 52 }
U --> CDN
GW@{ icon: "algomi:svc-api", label: "Reverse proxy cache", pos: "b", h: 52 }
CDN --> GW
APP@{ icon: "algomi:ext-device", label: "App instance: tiny local cache", pos: "b", h: 52 }
GW --> APP
R@{ icon: "algomi:data-bolt", label: "Redis: shared cache", pos: "b", h: 52 }
APP --> R
DB@{ icon: "algomi:data-bolt", label: "Database: its own buffer cache", pos: "b", h: 52 }
R --> DB
You've reached the free preview of this post.
Subscribe to the Blogs plan (₹99/mo) — or use any Algomi Suite, Career, Investor, or Trader plan — to keep reading.
See plans