Sweaty Imposter

hash(key) % N Versus Consistent Hashing

TradeoffSeniorStaffUpdated

Sharding 100GB of session data across 10 cache nodes, with occasional node additions/removals.

Short answer: Consistent hashing. Modulo remaps ~all keys when N changes.

The Two Options

A

hash(key) % N

B

Consistent hashing

Drill This: Your Pick First

The Better Pick

Option B

Consistent hashing

Modulo remaps ~all keys when N changes. Consistent hashing moves only ~1/N of keys, preventing cache stampedes during scaling.

When the Other One Wins

hash(key) % N

If the node count is truly fixed forever, modulo is simpler and has perfectly uniform distribution.