Scale with Redis Cluster

  • Shard placement, direct client routing and recovery when one primary fails.
100%
Shard AShard BShard CA slot belongs to one primary at a timeClient / applicationReplicationslot 511slot range Bslot 12304replicate Areplicate Breplicate CComputes a slot from the key bytes, consults its routing table and opens a direct connection to the slot owner.Cluster-aware clientCached slot mapOwns slot 511 for cart:{18}:items in this example.Primary A · Zone 1Slots 0–5460Replicates A’s shard. It can take ownership of A’s slots after eligibility checks and election.Replica of AZone 2Shares topology over the cluster bus and votes in replica elections. The application uses the data port for its commands.Primary B · Zone 2Slots 5461–10922Retains B’s subset of the keyspace. Restore and capacity planning must account for every shard.Replica of BZone 3Owns slot 12304. Both item and revision keys tagged {17} are routed here.Primary C · Zone 3Slots 10923–16383Replicates shard C. Placing replicas outside their own primary’s failure zone allows one zone failure in this three-zone example.Replica of CZone 1slot 511slot range Bslot 12304replicate Areplicate Breplicate C

Select a component to trace its direct connections. Drag to pan · Ctrl + wheel or pinch to zoom.

  • The client hashes a key into one of 16,384 slots. Each shard has a primary that serves its slots and a replica that copies that primary.
  • In this layout, cart:{17}:items and cart:{17}:revision share slot 12304 on C. Grouping them allows an atomic multi-key operation and concentrates their load on C.
  • If C fails, its eligible replica can win a vote from the surviving primaries and take C’s slots. Clients refresh their slot maps and reconnect to the new owner.
  • The 16,384 slots divide key ownership among primaries. Each replica follows a single shard.
  • Hash tags place related keys together. A busy tag concentrates its traffic on one shard even when the other shards have spare capacity.
Scale with Redis Cluster

Scale with Redis Cluster

Redis Open Source 7.2 architecture

Route keys from the client

  • The three-primary example assigns contiguous slot ranges. Redis Cluster supports different assignments and ownership changes.
  • Run node redis-slots.cjs. Both cart:{17}:items and cart:{17}:revision map to slot 12304, owned by C. The item key tagged {18} maps to 511 on A.
  • The hash uses the bytes between the first opening brace and its following closing brace when that substring is nonempty. Otherwise it hashes the entire key.
  • A same-slot atomic update can touch the two {17} keys. A multi-key command spanning slots can receive CROSSSLOT even when one primary happens to own both slots.
Calculate three keys’ slots offlinejavascript
'use strict';

// Run: node redis-slots.cjs
// This offline example hashes UTF-8 keys using Redis Cluster's CRC16/XMODEM.
function slot(key) {
  const bytes = Buffer.from(key, 'utf8');
  const open = bytes.indexOf(0x7b);
  const close = open < 0 ? -1 : bytes.indexOf(0x7d, open + 1);
  const input = close > open + 1 ? bytes.subarray(open + 1, close) : bytes;
  let crc = 0;
  for (const byte of input) {
    crc ^= byte << 8;
    for (let bit = 0; bit < 8; bit++) {
      crc = (crc & 0x8000) ? ((crc << 1) ^ 0x1021) & 0xffff : (crc << 1) & 0xffff;
    }
  }
  return crc % 16384;
}

function owner(number) {
  if (number < 5461) return 'A';
  if (number < 10923) return 'B';
  return 'C';
}
if (require.main === module) {
  for (const key of ['cart:{17}:items', 'cart:{17}:revision', 'cart:{18}:items']) {
    console.log(key, slot(key), owner(slot(key)));
  }
}
module.exports = {slot, owner};

Separate redirect handling from election

Condition Client action Topology consequence
MOVED for a slot Retry at the indicated owner and refresh slot topology Future requests should follow the refreshed mapping.
ASK during classic slot migration Retry that command at the target, preceded by ASKING on the same connection Keep the existing slot map for later requests until ownership changes.
C fails with A and B reachable Reconnect and learn the new owner after an eligible replica wins election The promoted replica takes C’s slots. Recent unreplicated writes may be missing.
  • Cluster nodes exchange failure and ownership state over the cluster bus. A replica normally needs authorization from a majority of slot-serving primaries for automatic failover.
  • With full-slot coverage required, loss of a shard without an eligible replacement can stop the cluster serving normal requests. Partial-coverage operation is a separate availability policy and still depends on majority-side reachability.

Size for the hottest owner

  • If the {17} keys alone generate 12,000 operations/s, moving other slots cannot split that tag’s work. Choose a smaller co-location domain when atomic operations allow it.
  • A fourth primary adds capacity to the system after slot redistribution. Test redirect handling and multi-key operations while migrating.
  • Include replica memory, replication traffic and failover-zone headroom. Three shards with one replica each need roughly two dataset copies before allocator, buffering and persistence overhead.