Try
↑ ↓ move↵ openesc close

Interview prep / Caching

Mid · Caching · System design interview question

Why is the Zipf distribution used to model cache workloads, and what does its skew parameter tell you?

Sketch your own answer first, then compare it with the one below.

A strong answer

In a Zipf-like distribution the key ranked k is requested with probability proportional to one over k raised to a power. A few keys account for a large share of requests, and there is a long tail of rarely requested keys.

Studies of web request traces found popularity of this shape, which is why Zipf is the standard synthetic workload for cache experiments.

The skew is that power. At zero every key is equally likely, so a cache is no better than its size relative to the keyspace. As skew rises, the same few keys dominate, so a small cache covers a larger share of traffic.

To size a cache with this, estimate the skew from a trace and plot hit rate against cache size. The curve flattens as the cache grows, because the long tail of rare keys adds little.

A caveat: real workloads also change over time, and a static Zipf model will not show how policies cope with that.

Sources

Learn it by running it

The caching and eviction lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms