Definition · Zipf popularityRank N keys from most to least requested. Under a Zipf popularity with exponent s ≥ 0, the key of rank i is requested with probability p_i = (1/iˢ)/H(N, s), where H(N, s) = 1 + 1/2ˢ + 1/3ˢ + … + 1/Nˢ is the generalised harmonic number.
s = 0 makes every key equally likely: H(n, 0) = n and p_i = 1/N. Larger s concentrates the requests on the head. Measured web and key-value workloads usually land between s = 0.7 and s = 1.2; this lesson uses integer exponents, for a reason given below.
Two things are being assumed and both are worth saying out loud. The first is the rank law itself, which is an empirical regularity rather than a theorem — workloads are measured and found to look like this, not derived and found to be this. The second is that the ranking is stable over the window you care about, which is false for news and true for a product catalogue.
Given the law, everything after it is addition. The share of the requests carried by the top k keys is the sum of the first k probabilities, and the normaliser cancels down to a ratio of two sums of the same shape.
k k
Σ p_i = (1/H(N,s)) Σ 1/i^s = H(k,s)
i=1 i=1 ──────
H(N,s)
uniform popularity (s = 0): H(k,0)/H(N,0) = k/N
Example · Fifty keys at s = 2H(5, 2) = 1 + 1/4 + 1/9 + 1/16 + 1/25 = 5269/3600. Dividing by H(50, 2) gives 90.06%: five keys out of fifty carry ninety per cent of the requests. One key on its own — two per cent of the catalogue — carries 61.53%, 30.77 times its share. Under uniform popularity those two numbers would be 10% and 2%.
Why this is the whole case for caching
A cache is worth building when a small store serves a large fraction of the requests, and the ratio H(k, s)/H(N, s) divided by k/N is exactly how much better than proportional you are doing. At N = 50 and s = 2 that multiple is 9.01 for the top five keys and 30.77 for the top one. At s = 0 it is 1 for every k, and a cache holding a tenth of the catalogue serves a tenth of the requests — which is the misconception, arrived at by computing it.
The multiple also shrinks as k grows, and that is the shape that decides how big a cache should be: the first key is worth thirty times its weight, the fiftieth is worth almost nothing. Cache Size and Hit Rate reads a required cache size off exactly this curve.
The one figure on this course that is not exact
H(n, s) is a finite sum of fractions, so it is an exact rational and the lab computes it that way, term by term, over arbitrary-precision integers. What goes wrong is not accuracy but readability: H(50, 2) is a fraction whose numerator and denominator each run to forty-three digits, and a page that prints it has stopped communicating.
So the lab prints the exact fraction while the catalogue has at most fifty keys, and above that it switches to a rounded value, marks the figure with a ~, and says on its own face that it has switched. Drag N to 200 and the top two keys read ~25.865% of the requests — one per cent of the catalogue carrying a quarter of the traffic, 25.87 times its share — with the tilde there to tell you the sum is no longer exact. Every other number on this course is a fraction.
The exponent is an integer here for a related reason: at a fractional s every term 1/iˢ is irrational and there is no exact fraction to print at all. Real workloads have fractional exponents, and the right way to use this lesson on one is to bracket it — compute the share at s = 1 and at s = 2 and report the interval, rather than quote a rounded number with a confidence it has not earned.