QA
Beginner LevelSystem Design & Architecture

What is Consistent Hashing and why is it essential for distributed caching clusters?

❓ Interview Prompt: Explain Consistent Hashing, Hash Ring, virtual nodes, node addition/removal, and preventing cache invalidation storms.

Standard modulo hashing ('hash(key) % N') causes 99% of cached keys to remap whenever a cache server node is added or removed from a cluster!

Consistent Hashing Solution:

Maps both keys and server nodes onto a virtual Hash Ring ($0$ to $2^{32}-1$):

β€’
Keys are assigned to the first server encountered moving clockwise on the ring.
β€’
Node Removal/Addition: Adding or removing a server node remaps ONLY $1/N$ of keys, preventing massive cache invalidation storms!

Code Implementation Example

markdown
Consistent Hashing Ring Diagram:

                 [Node A (Hash: 100)]
               /                      \
       [Key 1 (Hash: 50)]         [Key 2 (Hash: 200)]
             β”‚                          β”‚
             β–Ό                          β–Ό
      (Routes to Node A)        [Node B (Hash: 300)]
πŸ’‘Consistent Hashing virtual ring routing keys clockwise to target nodes.
🎯 Interview Key Takeaway

Use Consistent Hashing in distributed cache clusters to ensure smooth node scaling with minimal key remapping.

#System Design#Consistent Hashing#Distributed Caching#Beginner
Back to all System Design & Architecture Questions→

More System Design & Architecture Interview Questions

Beginner LevelSystem Design & Architecture

Explain the CAP Theorem and PACELC Theorem with real-world database examples.

Beginner LevelSystem Design & Architecture

What is Vertical Scaling (Scale Up) vs Horizontal Scaling (Scale Out)?

Beginner LevelSystem Design & Architecture

How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?