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β