Consistent Hashing

Quick Reference: Load Balancing | Hashing Internals | Step 2: Sharding


Quick Reference

AspectTraditional HashingConsistent Hashing
RebalancingRehash all keysMinimal key movement
Adding ServerAll keys moveOnly nearby keys move
Removing ServerAll keys rehashOnly affected keys move
Use CaseStatic serversDynamic server changes

Clear Definition

Consistent Hashing is a hashing technique that minimizes key redistribution when servers are added or removed. Keys are mapped to a hash ring, and each server handles keys in its range.

šŸ’” Key Insight: Consistent hashing enables dynamic scaling with minimal data movement, essential for distributed caching and databases.


Core Concepts

Hash Ring

  • Keys and servers mapped to ring
  • Each server handles keys clockwise from its position
  • Adding/removing server affects only nearby keys

Virtual Nodes

  • Multiple virtual nodes per physical server
  • Improves distribution uniformity
  • Reduces hotspots

Use Cases

  1. Distributed Caching: Redis, Memcached clusters
  2. Load Balancing: Request routing
  3. Database Sharding: Data distribution
  4. CDN: Content routing

Best Practices

  1. Use Virtual Nodes: Improve distribution
  2. Monitor Distribution: Check for hotspots
  3. Handle Failures: Replicate data across nodes

Quick Reference Summary

Consistent Hashing: Hash ring minimizes key movement when servers change.

Key Benefit: Dynamic scaling with minimal rebalancing.

Use For: Distributed caching, load balancing, sharding.


Previous Topic: Load Balancing ←

Next Topic: Hashing Internals →

Back to: Step 6 Overview | Main Index