A product page reads the same row from the database thousands of times a second. A cache in front of it makes reads fast, then brings its own problems: stale data, a stampede on a hot key and the question of where writes go.
What you learn
The cache-aside read path: look in the cache, fall back to the database, fill
TTL and invalidation: why a write must delete the cached copy
What a stampede on a hot key is, and how coalescing and jittered TTL stop it
Write-through vs write-back, and what each one risks
Recap
Five rules for a cache.
1) Cache-aside: read the cache, on a miss read the database and fill. 2) Every key has a TTL as a safety net. 3) A write deletes the key, after the commit. 4) Hot keys need coalescing and jittered TTLs. 5) Write-back only for data you can afford to lose.
A shop's server sits on one continent, its buyers on another. Images and scripts move to edge caches near the users: how a request reaches the edge, when it goes back to the origin, how to replace a file and what must never be cached.
What you learn
How an edge cache sits between users and the origin, and what a miss and a hit cost
Cache-Control decides what may be cached and for how long
Purge vs versioned URLs for replacing a file
An origin shield, and why private responses must never be cached
Recap
Five rules for a CDN.
1) Static files are served from an edge near the user; the origin only fills misses. 2) The origin sets Cache-Control explicitly on every response. 3) Replace files with versioned URLs; keep purge for emergencies. 4) An origin shield turns many edge misses into one. 5) Personal responses are private, no-store, always.