Definition · Hot keyA hot key is a single key that receives a disproportionate share f of the traffic to a dataset. Because every partitioning function maps one key to one shard, the whole of f·λ arrives at one node no matter how the function is chosen or how many shards there are. The remaining (1 − f)λ is spread by whatever the function does.
hottest shard's load, with one hot key
hottest(N) = f·λ + (1 − f)·λ/N
↑ ↑
no N goes to 0 as N grows
λ = 100 000 /s, f = 12%
N mean hottest imbalance above the floor
1 100 000 100 000 1.00× 88 000
16 6 250 17 500 2.80× 5 500
32 3 125 14 750 4.72× 2 750
128 781 12 688 16.24× 688
1 024 98 12 086 123.76× 86
floor = f·λ = 12 000 /s
Read the last column down. Sixty-four times the shards took the hottest shard from 17 500 /s to 12 086 /s, a reduction of 31%, and the remaining 12 086 is 12 000 of hot key plus 86 of everything else. Every further shard is buying a share of the 86. The imbalance column is going the other way — 2.80 times the mean at 16 shards and 123.76 times at 1 024 — because the mean is collapsing while the hottest shard is not.
This is the second of the three skews on this course that resharding does not fix, and it is the starkest. A hot range at least moves when you split it; a hot key does not move at all, because there is nothing in it to split. The asymptote is the shape “Graphs and Asymptotes” on the Algebra path describes: a curve falling toward a horizontal line it never meets, and the line is at f·λ.
Salting: making one key into several
Definition · SaltingSalting a key replaces it with s derived keys — key#0, key#1, …, key#(s−1) — choosing a suffix uniformly at random on each write. Writes to the original key are then spread over s distinct keys, which hash independently. A read must fetch all s pieces and combine them, so the operation the salt makes cheap is the write and the operation it makes expensive is the read.
The arithmetic is immediate: the hot term becomes (f/s)·λ and the rest is unchanged, so the hottest shard holds (f/s)·λ + (1 − f)λ/N. At f = 12%, λ = 100 000 /s, N = 16 and s = 8 that is 1 500 + 5 500 = 7 000 /s, against a mean of 6 250 /s. Where sixty-four times the shards bought a 31% reduction, eight salt pieces bought 60%.
Example · What the salt costs, stated two waysEvery read of the salted key now issues s = 8 requests instead of one, so reads of that key are 8 times as expensive. Across the whole read stream the multiplier is smaller, because only the hot key fans out: 1 − f + f·s = 0.88 + 0.96 = 1.84, so the fleet does 1.84 times the reads overall. Both numbers are true and they answer different questions — the first sizes the latency of a read of that key, the second sizes the fleet. Quoting only the second makes salting sound cheaper than it is for the request that actually touches the hot key.
Choose s from the target, not from habit. The lab reports that at these numbers a salt of 4 already brings the hottest shard within 1.5 times the mean, at a read multiplier of 1.36 rather than 1.84. Going to s = 16 gets the hottest shard to 6 250 /s — the mean exactly — for a read multiplier of 2.80. The last increments of balance are the expensive ones.
When not to salt
Salting is one of three answers and it is the one with a running cost. If the hot key is read far more than it is written, a cache in front of it removes the load without touching the partitioning at all — “Hit Rate and Backend Load” prices that. If the key is hot because of one client, a rate limit is cheaper than either. Salt when the traffic is genuinely write-heavy on a key that genuinely has to be one key, and then write down the read multiplier you accepted.
One more property worth stating plainly: f is measured, not assumed. It is the hot key's share of the traffic, and getting it from a sampled request log is usually easy. Everything on this page is a function of f, λ, N and s, so a designer who knows those four numbers can answer “will more shards help?” before anyone builds anything — and the answer, when f·λ is already above one node's capacity, is no.