We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
This idea carries a full system design question on its own. Each walks through the full answer.
System Design Masterclass · Caching Strategies
Free preview: the first 2 parts of this 9-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Caching Strategies
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
Every cache in this chapter so far has been something the application asked. It calls, it gets an answer, it decides what to do next. An cache sits in front, and answers before the application knows a request happened.

The key is built from the URL, not from anything the application chose. Freshness comes from a header on a response the application sent earlier and is no longer being asked about.
Read the whole lesson through that inversion. Every measurement below is a consequence of the cache being in front, and none of them can happen to a cache the application calls itself.
The lab starts a real origin that logs every request it receives, then sends 20,000 real requests over 200 pages drawn from a Zipf distribution. The origin sends Cache-Control: public, max-age=60 on everything, which is exactly what an application is supposed to do.

Every run served correct pages. Nothing errored, nothing was slow, and no application log contained anything unusual, and the origin did a hundred times more work in the first run than in the last.

Most frameworks create a session on the first response to every visitor, logged in or not, and send a Set-Cookie header with it. A shared cache is required to treat that response as belonging to one client.
The header is not wrong and the cache is not wrong. The application is telling a shared cache that this response is personal, and the cache is believing it.

This is a two-line change in most frameworks: do not start a session until something is put in it. Almost nobody makes it, because with no cache in front there is no visible consequence.
Look at the response headers of your own home page as a visitor with no cookies before doing anything else. If there is a Set-Cookie on it, no shared cache anywhere on the internet is storing that page, including every you are paying for.