Databases 9 min read

Why Does Redis Prefer Hash Slots Over Consistent Hashing?

Redis Cluster distributes data using 16,384 hash slots calculated via CRC16, a design that offers flexible slot allocation, simpler data migration, and better performance compared to traditional consistent hashing, and this article explains the slot mechanism, node scaling, client routing, and the reasons behind the 16K slot choice.

dbaplus Community
dbaplus Community
dbaplus Community
Why Does Redis Prefer Hash Slots Over Consistent Hashing?

Introduction

The article explains why Redis Cluster uses hash slots instead of the classic consistent hashing algorithm for key distribution.

Consistent Hashing Recap

Consistent hashing maps keys onto a 2^32 ring, using virtual nodes to balance data and reduce migration when scaling.

Redis Hash Slots

Redis Cluster divides the key space into 16,384 slots (2^14). Each key is processed with CRC16 and the result is taken modulo 16384 to determine its slot, which maps directly to a specific node.

Slot Allocation

Each Redis node stores the subset of slots it is responsible for. The node also records which slots belong to other nodes, enabling the client to locate the correct node for any key.

Adding Nodes

When a new node D is added, existing nodes transfer a portion of their slots to D, rebalancing the cluster (e.g., 4 nodes each get ~4096 slots). Administrators can use the CLUSTER ADDSLOTS command to assign a custom number of slots, allowing higher‑performance nodes to hold more slots.

Removing Nodes

When a node C is removed, its slots are redistributed among the remaining nodes, e.g., each of the two remaining nodes receives 8192 slots.

Client Access Flow

A client connects to any node, computes the slot via CRC16(key) % 16384, and checks which node owns that slot. If the key is not on the contacted node, the server returns a MOVED redirect with the target node’s address, and the client retries the command.

Smart Clients

Most language‑specific Redis clients implement a “smart” mode that maintains the slot‑to‑node mapping locally, eliminating the need for repeated MOVED redirects.

Why Hash Slots Over Consistent Hashing?

During scaling, slots can be reassigned flexibly without recomputing hashes for all keys, simplifying data migration.

Slot‑based migration moves whole slot ranges, which is more straightforward than moving individual keys in consistent hashing.

Slots can be unevenly allocated to match node performance, giving stronger nodes more slots.

Why 16,384 Slots?

Redis’s designers chose 2^14 slots because a cluster rarely exceeds 1,000 master nodes; 16 384 slots provide enough granularity while keeping the slot bitmap small (2 KB). Larger slot counts would increase heartbeat payload size and memory usage.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

databaseredisconsistent hashingcluster scalingHash SlotsCRC16
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.