Cluster — 16384 slots and the client routes
Redis Cluster shards by CRC16(key) mod 16384 with no proxy; clients cache a slot map and learn corrections via MOVED (permanent) vs ASK (transient, per-query), and configEpoch resolves slot-ownership conflicts after failover.
Sentinel buys availability with a single master. But you still only have one master's worth of write throughput. Cluster splits the keyspace across multiple masters — and pushes the routing logic into the client.
Scene 08
Cluster — 16384 slots and the client routes
- Watch
- Try it
- Predict
- Capture
The slot bar across the top is colored by owning master. The client holds a cached copy of that map. Watch a few queries hash to slots and land on the right master in one round trip.
Highlighted lines are the ones running in the diagram right now.
def send(cmd, key):slot = hashSlot(key)node = cachedMap[slot] # client-side routeresp = node.exec(cmd)if resp is -MOVED(slot, newOwner):cachedMap[slot] = newOwner # heal permanentlyreturn newOwner.exec(cmd) # retry oncereturn resp
def send(cmd, key):slot = hashSlot(key)node = cachedMap[slot]resp = node.exec(cmd)if resp is -ASK(slot, target):# one-shot: prefix ASKING, route to targettarget.exec(ASKING) # ONCEreturn target.exec(cmd)# cachedMap[slot] is left UNCHANGEDreturn resp
def hashSlot(key):lo = key.find('{')if lo != -1:hi = key.find('}', lo + 1)if hi > lo + 1:key = key[lo + 1 : hi] # hash only the tagreturn crc16(key) % 16384
def handleQuery(cmd, key):slot = hashSlot(key)if slot not in myOwnedSlots:return -MOVED(slot, owners[slot])if slot in MIGRATING and key not local:return -ASK(slot, migrating[slot].target)if slot in IMPORTING and not asking_flag:return -MOVED(slot, owners[slot])return execute(cmd, key)
Where this sits in Build Redis
Scene 08 of 10, in the Shard & ship act — Cluster slots, MOVED/ASK, and the design canvas.. CRC16 mod 16384, MOVED vs ASK (permanent vs transient), hash tags, configEpoch — and why sharding alone is not HA.
Up next. Design canvas — you've seen every knob. Now assemble them into a real deployment and name the trade you're making, out loud, against the SLO.
Designs that use this
- URL ShortenerShorten a long URL. Read-heavy. Don't collide.
- Distributed Rate LimiterEnforce a per-key request limit across a fleet of enforcers — accurately, in under a millisecond, without becoming the outage.
- Twitter / X TimelinePush or pull? Both. The canonical fanout problem.
- Uber / Lyft — Match Drivers and RidersMatch a rider to the closest acceptable driver in under 3 s. Geohash, S2, surge.