# Caching — System Design: Architecture, Scale and Trade-offs

Source: https://www.skillbyai.com/en/system-design/sd-caching

> Cut latency and database load with layered caching, cache-aside and write-through patterns, TTLs and eviction policies.

## Where caches live

Browser, CDN, reverse proxy, application memory, and a shared store like Redis. Each layer absorbs reads so the database sees only the misses.

## Write strategies

**Cache-aside**: app loads on miss, writes DB and invalidates. **Write-through**: write cache + DB together. **Write-back**: write cache now, DB later (fast, risky).

## Always set a TTL

An expiry bounds staleness and stops a poisoned entry living forever. Add jitter to TTLs so keys don't all expire at once (thundering herd).

**Quiz:** Which eviction policy removes the entry unused for the longest time?

- [ ] FIFO
- [ ] Random
- [ ] MRU (most recently used)
- [x] LRU

*Answer:* LRU. LRU (Least Recently Used) evicts the coldest entry by last access time.
