Try
↑ ↓ move↵ openesc close

Interview prep / Partitioning

Mid · Partitioning · System design interview question

Why do many systems create far more partitions than machines, and how does that relate to hash mod N and consistent hashing?

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

A strong answer

If partition equals hash modulo the number of machines, adding a machine changes the divisor and moves most keys. To avoid that, create many partitions up front, say a few hundred per machine, and assign whole partitions to machines. The key to partition rule never changes. Only the map from partitions to machines does, and adding a machine means moving a few partitions to it.

Consistent hashing with virtual nodes reaches a similar result by a different route. Keys hash onto a ring, the ring is cut into many small arcs, and a joining node takes over some of them. Both limit movement to roughly the new machine's fair share.

The partition count is a real decision. Too few and load cannot be balanced finely or the cluster grown far. Too many and each partition carries overhead. The partition is also the unit of movement, replication and failure.

Sources

Learn it by running it

The partitioning 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