Route Cache Keys to Nodes With a Consistent Hash Ring

Last updated: November 29, 2026

Quick Overview

A session cache cluster is resized often, and with modulo hashing every resize remaps almost every key and floods the database with misses. Implement a consistent hash ring with virtual nodes, weights, and replica lookup.

Amazon
Software Engineering Fundamentals
Software Engineer
Amazon
November 29, 2026
Software Engineer
System Design Round
Software Engineering Fundamentals
Hard

0

0

0 solved


A session cache cluster is resized often, and with modulo hashing every resize remaps almost every key and floods the database with misses. Implement a consistent hash ring with virtual nodes, weights, and replica lookup.

Consistent hashing underpins the original Dynamo paper and many Amazon caching tiers, and interviewers use it to check whether you understand key movement, load balance, and replica placement rather than just the picture of a circle.

What the Interviewer Expects
  • Explains why modulo hashing remaps about $\frac{n}{n+1}$ of keys on resize
  • Places nodes at many virtual points to balance load
  • Finds the owner by binary search clockwise from the key's hash
  • Returns distinct physical nodes for replicas
  • Shows that adding a node only moves keys onto that node
Key Topics to Cover
consistent hashing
virtual nodes
load balancing
replication
sharding
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How many virtual nodes do you need, and what does it cost?
  • How would you handle a hot key that overloads one node regardless of hashing?
  • How does rendezvous (highest random weight) hashing compare?
  • What happens to in-flight requests during a membership change?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • get(key, replicas) returns the owning node and the next distinct nodes clockwise.
  • Adding or removing a node moves only about 1n\frac{1}{n} of keys.
  • Load roughly even; nodes with weight 2 get a...
High-Level Design

Hash each node at vnodes * weight positions (node#i) on a 64-bit ring stored as a sorted list plus a position to node map. A key is hashed and owned by the first position strictly clockwise (`bise...


Submit Your Answer
Markdown supported