Problem statement
Design the object model and public API for a consistent-hash ring that maps keys to nodes so that adding or removing a node reshuffles only a small fraction of keys, using virtual nodes to keep the load balanced.
Operating context. One process, an in-memory ring — a sorted map from hash positions to nodes. Each physical node is placed at V virtual positions to smooth the key distribution. A key routes to the first node clockwise from the key's hash. Routing lookups dominate; membership changes (adding or removing a node) are occasional. This is the routing library only, not the cluster it feeds.
Out of scope. The actual data replication and networking, gossip / membership protocols, capacity-weighted nodes as a hard requirement (name the weighting seam), rebalancing data movement between nodes, and any persistence of the ring itself.
What to produce. The class model (the sorted ring structure, virtual-node placement, and a pluggable hash strategy), the public API (addNode, removeNode, getNode(key), getNodes(key, replicaCount), nodes), the clockwise-successor lookup over the sorted ring, and how the virtual-node count trades memory for distribution smoothness — state the minimal-remap property explicitly.
Requirements
This assessment is a Premium feature.
The statement above is free to read. The functional and non-functional requirements, and the graded canvas that scores your design against them, come with Premium.
Topics
- System Design LLD
- Ds Hash-Ring
- Hashing Consistent
- Oop Solid
- Patterns Strategy