Performance
Cache Stampedes
When a popular item disappears, we stop thousands of people from rushing the kitchen at once. One person orders, and everyone else waits for that fresh batch.
1
Cache stampede
When the cache forgets, everyone asks at once
A cache is a notepad with quick answers. When the answer expires, every request goes to the slow database at once. The database can't handle the rush and falls over. The fix: let one request do the work. Everyone else waits for the result.
No lock: everyone hits the database. It crashes.
With lock: one request rebuilds. The rest wait.
Press red for chaos. Press green for one rebuild while everyone else waits.