Design consistent hashing for sharding
DoorDashSoftware Engineer · OnsiteLast updated
This question evaluates understanding of consistent hashing, replica placement, dynamic membership, weighted load distribution, rebalancing impact, and related distributed-systems competencies for routing and sharding.
Design and implement a consistent-hashing based router that maps arbitrary keys to backend servers. Requirements: (
- Describe the hash ring, token assignment, and use of virtual nodes to smooth load; (
- Support addServer(id, weight) and removeServer(id) with minimal key movement; (
- Implement getServer(key) and explain the expected percentage of keys that move when servers join/leave; (
- Extend to replicate each key to R distinct servers and discuss read/write semantics under failures; (
- Analyze time/space complexity and storage overhead.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.