← All concepts
Data & storage
Caching
Keep copies of frequently read data in fast memory so most requests never reach the database.
Most large systems are read-heavy and a small fraction of data gets most of the reads. Putting that hot data in an in-memory store (or at a CDN edge) cuts latency from milliseconds to microseconds and shields the database from load.
The hard parts are deciding what to cache, how long to keep it, and what happens when the underlying data changes.
See it in action
Step through the scenarios on the diagram.
Laying out diagram…
1/2The app requests product 42.
- App
- — Asks for product 42
- Product service
- — Applies cache-aside
- Cache
- — Hot products, 5-minute TTL
- Database
- — Source of truth
How it works
- Cache-aside: read the cache; on a miss, read the DB and populate the cache. The most common pattern.
- Write-through: write to cache and DB together so the cache is always fresh.
- Write-back: write to cache and flush to the DB later — fast but risks loss.
- Eviction (LRU/LFU) and TTLs bound memory; versioned keys avoid explicit invalidation.
Trade-offs
- Stale reads until the TTL expires or the key is invalidated.
- Cache stampede when a hot key expires — use request coalescing or early refresh.
- Another system to run, monitor and size.
Seen in
- YouTubeGlobal video upload, transcode, and streaming
- NetflixGlobal video streaming with microservices
- InstagramPhoto/video sharing with social graph feeds
- Twitter / XShort posts, follow graph and real-time home timelines
- AmazonHigh-traffic e-commerce marketplace
- URL shortenerShort links with billions of redirects
- API rate limiterFair-use limits checked on every request in under a millisecond
- Search autocompleteSuggestions on every keystroke in under 100 ms
- PastebinShare text snippets by short link
- DropboxFile sync across every device
- Google MapsMap tiles, place search, routing and live traffic
- BookMyShowMovie and event tickets with live seat selection
- MakeMyTripFlights and hotels aggregated from many suppliers
- AirbnbSearch, book and message for vacation rentals
- Meeting schedulerFind a time, book a room, invite everyone
- Car rentalReserve a car by class, pick up, drive, return
- Zomato / food deliveryRestaurant discovery, ordering and live delivery tracking
- QuoraQuestions, answers, votes and a personalised feed
- LinkedInProfiles, connections, feed, messaging and jobs
- Live sports scoresReal-time scores, commentary and alerts for millions
- Redis ClusterDistributed in-memory data store