Skip to content

Lesson 3 of 9 · 26m

Redis Cluster: Slots, Sharding, and the Limits You Accept

How hash slots distribute keys, what cluster mode does to multi-key operations, and when Cluster is the wrong answer.

Redis Cluster is not just 'replication but bigger.' It is a sharded system with 16,384 hash slots, independent masters, replica failover, gossip, redirections, and hard semantic limits. It buys horizontal write scaling and large datasets. In exchange, it takes away the comfortable assumption that any two keys can be used in one atomic operation.

Slots are the unit of ownership

Every key maps to exactly one slot:

slot = CRC16(key) mod 16384

Each master owns a range of slots. Clients use MOVED and ASK responses to find the current owner:

-MOVED 3999 10.0.4.18:6379

Cluster-aware clients cache the slot map and refresh it as ownership changes. A proxy or client that does not understand redirections is not cluster-compatible merely because it can open a TCP connection.

Multi-key commands only work when all keys are in the same slot. Curly braces force the hash input:

cart:{user42}:items
cart:{user42}:coupon
session:{user42}:refresh

Only user42 participates in the hash, so these keys colocate. This enables atomic MGET, Lua scripts, transactions, and sorted-set operations within one user's data. It does not create global atomicity.

Choose tags deliberately. One hot tag can concentrate a large fraction of traffic on one shard.

Resharding is movement, not copying magic

Moving slot 3999 means migrating its keys while traffic continues. CLUSTER SETSLOT, MIGRATE, and the higher-level resharding tools coordinate ownership, but the workload still pays network and CPU cost.

Do not reshard during your peak because a dashboard looks uneven that afternoon. Measure keys, memory, and command load per node; uneven key count is not automatically a problem.

Cluster changes the application contract

Cluster mode restricts or complicates:

  • cross-slot multi-key operations;
  • Lua scripts touching undeclared or cross-slot keys;
  • SELECT databases beyond database 0;
  • blocking operations with topology-sensitive behavior;
  • naive client connection pooling.

Publish/subscribe and keyspace notifications also need cluster-aware design because events are scoped by node or shard depending on the feature and Redis version.

When not to use it

If one well-sized primary plus replicas can handle your writes and memory, do not operate Cluster because it sounds more professional. A single-node topology has fewer moving parts, richer semantics, easier debugging, and less client complexity.

Cluster earns its complexity when dataset size, write throughput, or availability isolation genuinely exceed one shard's capacity.

Field notes

  • CLUSTER KEYSLOT somekey is the fastest way to verify whether two keys colocate.
  • Replicas in Cluster improve availability, not read capacity unless your client deliberately uses replica reads and accepts staleness.
  • requirepass and ACL credentials must be consistent across nodes; otherwise failover becomes a credentials incident.
  • During failover, CLUSTER FAILOVER manual operations are controlled. CLUSTER RESET is not a maintenance command — it is a identity-erasing hammer.
  • Infrastructure automation must understand slots. Blindly round-robining writes across masters is corruption by load balancer.

Was this lesson helpful?

Sign in to rate