36/37
Part 6 of 6 · Follow-upsLearn and do

Spread it over machines with a hash every process agrees on

Pick the machine for a key with a hash that every process agrees on. Python's own hash() of a string changes from one interpreter to the next: hash('user:42') % 4 in six fresh interpreters gave 1, 2, 0, 3, 0 and 1. zlib.crc32(b"user:42") % 4 is 2 every time.

Plain modulo has its own problem when the cluster grows.

Predict

Keys go to machine crc32(key) % 4. You add a fifth machine and switch to % 5. About what share of keys move?

Pick an answer above to see the rest