system flow
👤
01
Client
Users / apps make requests
🖥️
02
Application
Checks cache before querying DB
03
Cache Layer
Redis / Memcached — in-memory fast store
🗄️
04
Database
Primary store — MySQL, PostgreSQL
Without cache
Every hit = DB hit
  • Higher latency
  • More DB load
  • Lower scalability
← Select a component to explore it
1
Client requestSends to application
2
Check cacheApp looks up key
3a
Cache hit ✓Return fast
OR
3b
Cache miss ✗Fetch from DB
4
Get from DBPrimary store
5
Store in cacheFor next time
6
Return dataTo client
← Select a step to explore it
Benefits of caching
Better Performance
Serve from memory, not disk
📉
Reduced DB Load
Fewer queries hit the primary store
Improved Scalability
Handle more traffic without DB scale
💰
Cost Efficient
Fewer compute cycles on the DB tier
← Select a benefit to explore it
Common cache patterns
Cache-Aside (Lazy Loading)
App manages cache. Load data on demand.
Write-Through
Write to cache and DB simultaneously.
Write-Behind (Write-Back)
Write cache first, DB asynchronously later.
Cache Invalidation
Remove or expire stale entries.
← Select a pattern to explore it
💡
Key takeaway: Caching is a powerful technique to make systems faster and more scalable by keeping frequently used data close to the application — but the hard problem is cache invalidation: knowing when data is stale and needs to be refreshed.