This question evaluates understanding of consistent hashing, virtual nodes, sorted-map ring representation, replication and quorum strategies, membership changes and failure handling, complexity analysis, and testing considerations for distributed key-value or cache sharding systems.

You are building a client-side library to map arbitrary keys to backend nodes (cache/storage shards) that can be added or removed at runtime with minimal remapping. Represent the consistent hash ring with a sorted map (e.g., a TreeMap keyed by 64-bit hash tokens). Lookups should find the next node clockwise from a key's hash, with wrap-around to the beginning of the ring.
Assume a single-process demo is fine. Use any language with a sorted map (e.g., TreeMap) and include code for the library and a brief example.
Login required