Distributed Caching: Redis Cluster vs Memcached
Scale caching horizontally: Redis Cluster (16,384 hash slots), Memcached multithreaded architecture, replication, and failover.
01.1. How Redis Cluster Shards Data Across 16,384 Hash Slots
A single Redis server is bounded by single-core CPU execution and single-node physical RAM limits (typically 32GB to 64GB). To scale beyond these boundaries to terabytes of cache memory and millions of operations per second, Redis Cluster distributes data across a horizontally scalable sharded cluster.
Unlike classical distributed hash rings, Redis Cluster uses 16,384 fixed Hash Slots:
The Slot Mapping Formula:
Slot = CRC16(key) \pmod{16384}
- Slot Allocation: The 16,384 slots are divided among active master nodes (e.g., in a 3-master cluster: Master 1 holds slots
0-5460, Master 2 holds5461-10922, Master 3 holds10923-16383). - Client-Side Smart Routing: Redis smart clients (e.g., Jedis, ioredis, redis-py) cache the cluster slot topology map in memory. When executing
GET user:8492, the client calculatesCRC16("user:8492") \pmod{16384} = 7210, and connects directly to Master 2 in a single network hop. -MOVEDRedirects: If a slot is migrated during cluster rebalancing, the old node returns a-MOVED 7210 10.0.1.2:6379error, instructing the client to update its cached topology map and retry.
Redis Hash Tags: Multi-Key Atomicity
By default, Redis operations involving multiple keys (MGET, MSET, Lua scripts, transactions) require all keys to reside in the same hash slot.
- Hash Tag Syntax: Enclosing part of a key in curly braces
{...}forces Redis to hash only the substring inside the braces:- Key 1:
{user:101}:profile→hashes"user:101" - Key 2:
{user:101}:orders→hashes"user:101" - Both keys hash to the exact same slot, enabling atomic transactions and joins on the same Redis shard!
- Key 1:
Redis Cluster 16,384 Hash Slot Distribution 🌐
Redis Cluster 16,384 Hash Slot Distribution 🌐
Keys mapped to hash slots via CRC16(key) mod 16384.
Unlock Topic #104: Distributed Caching: Redis Cluster vs Memcached
You are viewing a preview. The full in-depth engineering deep dive, interactive simulators, architecture flowcharts, and self-assessment quizzes for this topic are available with Pro or Lifetime Access.
Failure modes, high-throughput bottlenecks, and real FAANG implementation decisions.
Interactive system topology diagrams, live parameter simulators, and downloadable SVG charts.
Staff-level multiple-choice quiz questions with instant feedback and answer explanations.
Firebase Google authentication automatically syncs your completed topics and quiz scores.
How clear and staff-actionable was this system breakdown?