We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Caching Strategies
Free preview: the first 2 parts of this 12-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”
Lazy loading is the default way almost every cache in the world is filled. A request arrives, the cache is checked, and if the value is not there the application fetches it, stores it, and returns it. The next request for that key is a hit. Nothing has to be published, nothing has to be predicted, and nothing has to be maintained.
Every sentence in that description is true. The one it leaves out is who paid for it.

The person who pays is chosen at random and gets no benefit from their own wait. They took the slow path so that everybody who asks for the same thing afterwards does not.
That is not an argument against lazy loading. It is the right default nearly everywhere, and the rest of this lesson will say so more than once. It is an argument for knowing the size of the bill, because the number is much larger than the phrase self-filling suggests.
The way to find out is to count. A hundred thousand requests were drawn from a Zipf distribution over twenty thousand possible keys, which is the standard model for how real traffic distributes itself across a catalogue: a small number of very popular items and a long tail of things asked for once or twice. Then the same stream was replayed five times, warming a different number of the most popular keys before each run.

With nothing warmed, 13,259 separate users paid the full slow path, which is one for every distinct key the traffic touched. That is 13.3 percent of all requests, and the mean across the whole run was 27.4 milliseconds.
The mean is the first thing to throw away. Look at the column and it barely moves: 27.4 milliseconds at the top, 23.7 at the bottom, while thousands of users stop waiting two hundred milliseconds each. A four millisecond difference in the summary statistic corresponds to ten thousand people no longer waiting.

The latency here has exactly two values and nothing in between. Their average is a point where no measurement landed. No request took 27 milliseconds. They took 1 millisecond or they took 200.
produces bimodal distributions by construction, which makes the mean the least informative number you can quote about one. The statistic that describes what happened is the share of requests that took the slow path.