Home/Labs/Redis Cluster Slot Router
All 280 Labs
INTERACTIVE LAB🌐

Distributed Caching: Redis Cluster vs Memcached Lab (Interactive)

Type real keys, compute CRC16 mod 16,384 slots, route them to shards, and kill a master to compare failover behavior. Route keys through Redis Cluster’s fixed hash-slot space, test hash-tag co-location, and contrast replica failover with Memcached node loss.

Redis Cluster Hash-Slot Router

Compute CRC16(key) mod 16,384 for real, watch keys land on shards, and see hash tags co-locate keys.

Cluster Topology

Route a key

Live CRC16 computation
hash target: user:8492
slot = CRC16 ÷ mod 16384 = 11118
shard: Master 3 [10923–16383]
Slot space 0 → 16383 distributed across masters
0amber marker = key's slot 1111816383
Routed keys (client-side smart routing, 1 hop)

Route keys to build the slot map…

per-shard load: M1:0 M2:0 M3:0
With hash tags ON, `{user:101}:profile` and `{user:101}:orders` both hash the substring "user:101" → identical slot → MGET/Lua transactions stay atomic on one shard. Route both presets to prove it.

How It Works Under the Hood

A single Redis process is capped by one core and one box of RAM, so Redis Cluster partitions the keyspace into 16,384 fixed slots with the formula CRC16(key) mod 16384, assigning slot ranges to masters that each keep a replica; gossip on the cluster bus elects a new master when one dies. Smart clients cache the slot map and hit the right shard in one hop, following -MOVED redirects during rebalancing. Multi-key atomicity requires same-slot co-location, achieved with hash tags like {user:101}. Memcached instead offers multithreaded simple key-value speed with no replication — a dead node means a shard-sized miss wave.

Core Architectural Principles

  • Slot = CRC16(key) mod 16,384; slot ranges move between masters for zero-downtime rebalancing via -MOVED.
  • Hash tags {user:101} force related keys into one slot, enabling MGET, Lua, and transactions on a shard.
  • Redis: single-threaded event loop, rich types, RDB/AOF, replica auto-failover. Memcached: multithreaded, pure KV, no persistence.
Interview Round Script

When sharding the cache tier, recite the slot formula — "CRC16(key) mod 16,384, ranges owned by masters with replicas" — because fixed slots make rebalancing a range move rather than a ring rehash. Show operational maturity with hash tags for multi-key atomicity, and choose Memcached explicitly when you have big multi-core boxes caching simple page fragments with failover delegated to the client.

Key Trade-Offs

Cluster terabyte-scale capacity and automatic failover versus Memcached’s raw multi-core simplicity with none of either.

Related Curriculum Chapter

Distributed Caching: Redis Cluster vs Memcached

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs