Low Level Design: Consistent Hashing Deep Dive

Introduction

Consistent hashing assigns keys to nodes such that adding or removing a node remaps only K/N keys on average, where K is the total number of keys and N is the number of nodes. In contrast, naive modulo hashing (key % N) remaps nearly all keys when N changes. Consistent hashing is critical for distributed caches, databases, and load balancers that must scale without wholesale cache invalidation or data migration.

Hash Ring

Both keys and nodes are mapped to points on a circular hash space ranging from 0 to 2^32 – 1. Node n maps to hash(n) on the ring; key k is assigned to the first node clockwise from hash(k). When a node is added, the new node takes over the portion of keys previously owned by its clockwise neighbor. When a node is removed, its keys are reassigned to its clockwise successor. In both cases, only K/N keys are remapped on average. The weakness of basic consistent hashing is uneven distribution: with few nodes, hash positions may cluster and leave some nodes handling far more keys than others.

Virtual Nodes

Each physical node maps to V virtual nodes on the ring, typically 100 to 200. This solves several problems: (1) with N*V points on the ring, load distributes far more uniformly; (2) when a node is added, it draws keys evenly from all existing nodes rather than only from its single clockwise neighbor; (3) heterogeneous capacity is handled naturally — a more powerful node receives more virtual node assignments proportional to its capacity. The downside is memory overhead for storing the ring structure, though at V=200 this is entirely manageable. Cassandra and DynamoDB both use virtual nodes (vnodes) for this reason.

Load Imbalance and Bounded Loads

Even with virtual nodes, variance in load distribution exists and can become significant under skewed key access patterns. Google’s 2017 bounded load consistent hashing adds a hard constraint: no node may handle more than (1 + epsilon) times the average load. When the assigned node is at capacity, the algorithm probes the next clockwise node on the ring. With epsilon = 0.25, load stays near-uniform with only slightly increased average probe count. Google uses this approach in the Maglev load balancer to ensure backend servers receive balanced traffic even when consistent hashing alone would create hotspots.

Rendezvous Hashing (Highest Random Weight)

Rendezvous hashing is an alternative to the ring structure. For key k, assign it to the node n* = argmax over all nodes n of hash(k, n). Every node independently computes the hash of the (key, node) pair and the node with the highest hash value wins. No shared ring data structure is required. The algorithm produces consistent results: any node that knows the node list computes the same assignment. On node removal, affected keys are reassigned to the node with the second-highest hash for each key. The cost is O(N) computation per lookup, acceptable for CDN origin selection where N is small and correctness matters more than lookup speed.

Jump Consistent Hashing

Jump consistent hashing achieves O(1) time and O(1) space for consistent hashing when nodes are numbered sequentially. The algorithm is: b = -1, j = 0; while j < num_buckets { b = j; key = key * 2862933555777941757 + 1; j = floor((b + 1) * (2^31 / ((key >> 33) + 1))) }; return b. The constraint is that nodes must be numbered sequentially and new nodes can only be added at the end — arbitrary node removal is not supported. This makes jump consistent hashing ideal for scenarios where the node count grows monotonically, such as storage shards that are never removed. It is extremely fast in practice due to its minimal computation.

Applications

Consistent hashing is foundational in distributed systems. Memcached and Redis clusters use client-side consistent hashing to map cache keys to specific nodes, ensuring cache hits remain stable when nodes are added or removed. DynamoDB and Cassandra use a partition ring where each partition key maps to a primary node and its replica set. CDN providers use consistent hashing (often rendezvous hashing) to map content URLs to edge servers, ensuring a given URL is consistently served by the same edge node to maximize cache hit rates. The core guarantee — that only K/N keys are remapped per node change — is what makes horizontal scaling practical in all of these systems.

See also: Meta Interview Guide 2026: Facebook, Instagram, WhatsApp Engineering

See also: Uber Interview Guide 2026: Dispatch Systems, Geospatial Algorithms, and Marketplace Engineering

See also: Scale AI Interview Guide 2026: Data Infrastructure, RLHF Pipelines, and ML Engineering

See also: Netflix Interview Guide 2026: Streaming Architecture, Recommendation Systems, and Engineering Excellence

See also: LinkedIn Interview Guide 2026: Social Graph Engineering, Feed Ranking, and Professional Network Scale

See also: Airbnb Interview Guide 2026: Search Systems, Trust and Safety, and Full-Stack Engineering

See also: Databricks Interview Guide 2026: Spark Internals, Delta Lake, and Lakehouse Architecture

See also: Anthropic Interview Guide 2026: Process, Questions, and AI Safety

See also: Atlassian Interview Guide

See also: Coinbase Interview Guide

See also: Shopify Interview Guide

See also: Snap Interview Guide

See also: Lyft Interview Guide 2026: Rideshare Engineering, Real-Time Dispatch, and Safety Systems

See also: Stripe Interview Guide 2026: Process, Bug Bash Round, and Payment Systems

Scroll to Top