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
Route keys to build the slot map…
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.
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.
Cluster terabyte-scale capacity and automatic failover versus Memcached’s raw multi-core simplicity with none of either.