9001. Consistent Hashing Ring

Place servers on a hash ring of size ring (positions 0..ring-1) at the given positions, then route each key: a key hashes to position (key % ring) and belongs to the first server clockwise from that position (wrapping around). Return the server that owns each key. This is the trick behind Cassandra, DynamoDB and memcached clients: adding or removing one server moves only the keys that fall in its arc, not every key.

Patterns: hashing, binary-search, design. Difficulty: medium.

Open in Dryrun