← Lessons

quiz vs the machine

Gold1480

Databases

Redis Cluster Sharding

Spreading keys across nodes with sixteen thousand hash slots.

5 min read · core · beat Gold to climb

Beyond One Node

A single Redis node is bounded by its RAM and one CPU core for command execution. Redis Cluster scales out by sharding the keyspace across many nodes so the dataset and throughput grow horizontally.

Hash Slots

Cluster divides the keyspace into 16384 hash slots. Each key is hashed to a slot, and every slot is owned by exactly one primary node. To find a key, you find its slot, then the node that holds that slot.

  • Keys are routed by CRC of the key name modulo 16384.
  • Clients cache the slot to node map and redirect on a MOVED response when it changes.

Keeping Related Keys Together

Multi key commands only work when all keys live in the same slot. Hash tags, a substring in braces, force keys to hash on just that part, so user braces 42 braces profile and user braces 42 braces cart share a slot and can be used together.

Resharding and Failover

Slots can be migrated between nodes to rebalance as you add hardware. Each primary can have replicas; if a primary fails, a replica is promoted so its slots stay available.

Key idea

Redis Cluster shards keys across 16384 hash slots owned by primary nodes, using hash tags to colocate related keys and slot migration to rebalance.

Check yourself

Answer to earn rating on the learn ladder.

1. How many hash slots does Redis Cluster use?

2. Why use a hash tag like braces around a user id in keys?

3. What does a MOVED response tell a client?