Cache Invalidation
Handle the hardest part of caching without shipping stale experiences.
Curriculum
System Design Foundations
Scalability Basics
Database Design
Cache Invalidation — Beginner Friendly System Design Guide
Why Caching Creates Problems
Caching makes applications:
- faster
- cheaper
- scalable
But there is one big challenge:
What happens when original data changes?
If cache still shows old data:
Users see stale information
This problem is called:
Cache Invalidation
What Is Cache Invalidation?
Cache invalidation means:
Removing or updating old cached data when actual data changes.
Real Example — Blinkit Inventory
Suppose Blinkit has:
1 milk packet left
Inventory cached in Redis.
User A buys it.
Database updates:
Stock = 0
But cache still contains:
Stock = 1
Now User B also orders.
Problem:
- overselling inventory
Without Cache Invalidation
Database Updated
│
▼
Old Cache Still Exists ❌
│
▼
Users See Wrong Data
With Cache Invalidation
Database Updated
│
▼
Invalidate Cache
│
▼
Next Request Gets Fresh Data
Common Cache Invalidation Strategies
1. TTL (Time To Live)
Cache automatically expires after fixed time.
Example
Cache expires after 5 minutes
TTL Flow
Store Data In Cache
│
▼
TTL Countdown Starts
│
▼
Cache Auto Expires
Best For
- product lists
- news feeds
- homepage data
Problem
Users may still see:
- old data until expiry
2. Manual Invalidation
Application deletes cache immediately after data update.
Flow
Update Database
│
▼
Delete Cache
│
▼
Fresh Data Loaded Again
Best For
- inventory
- payments
- booking systems
Real Example — Swiggy
Restaurant changes:
OPEN → CLOSED
Cache must update quickly.
Otherwise:
- users may place invalid orders.
3. Cache-Aside Pattern
Most common industry approach.
Application:
- checks cache first
- queries database if cache miss happens
Read Flow
User Request
│
▼
Check Cache
│ │
Hit Miss
│ │
▼ ▼
Return Query Database
Cache Data
Update Flow
Update Database
│
▼
Invalidate Cache
Why Cache Invalidation Is Hard
Modern systems may have:
- browser cache
- CDN cache
- Redis cache
All can become stale.
Multi-Level Cache Flow
Browser Cache
│
▼
CDN Cache
│
▼
Redis Cache
│
▼
Database
Real Example — YouTube Thumbnail Update
Creator changes thumbnail.
Need to invalidate:
- browser cache
- CDN cache
- backend cache
Otherwise users still see:
- old thumbnail
Common Beginner Mistakes
| Mistake | Problem |
|---|---|
| Long cache expiry | Stale data |
| Cache everything | Wasted memory |
| Forget invalidation | Wrong user experience |
Final Mental Model
Caching improves speed.
Invalidation keeps data correct.
Both are equally important.
One-Line Interview Definition
Cache invalidation is the process of removing or refreshing stale cached data when the original source of truth changes.
Module context
From browser cache to Redis clusters and CDNs. Caching strategies that turn slow apps into fast ones, with real-world invalidation patterns.