Limited Offer

30% OFF Lifetime Access ($139) with code SYSTEM30

TOPIC #104Intermediate 9 min read

Distributed Caching: Redis Cluster vs Memcached

💡
Core Architecture Summary

Scale caching horizontally: Redis Cluster (16,384 hash slots), Memcached multithreaded architecture, replication, and failover.

Key Glossary Concepts in this TopicAll Glossary Terms

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}

  1. 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 holds 5461-10922, Master 3 holds 10923-16383).
  2. 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 calculates CRC16("user:8492") \pmod{16384} = 7210, and connects directly to Master 2 in a single network hop.
  3. -MOVED Redirects: If a slot is migrated during cluster rebalancing, the old node returns a -MOVED 7210 10.0.1.2:6379 error, 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!

Redis Cluster 16,384 Hash Slot Distribution 🌐

PRO Architecture Blueprint

Redis Cluster 16,384 Hash Slot Distribution 🌐

Keys mapped to hash slots via CRC16(key) mod 16384.

Redis Cluster 16,384 Hash Slot Distribution 🌐
100%
Rendering visual architecture flowchart...
PRO & LIFETIME CURRICULUM

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.

Production Deep Dive

Failure modes, high-throughput bottlenecks, and real FAANG implementation decisions.

Interactive Blueprints

Interactive system topology diagrams, live parameter simulators, and downloadable SVG charts.

Knowledge Assessment

Staff-level multiple-choice quiz questions with instant feedback and answer explanations.

Cross-Device Progress Sync

Firebase Google authentication automatically syncs your completed topics and quiz scores.

Rate This Architecture Chapter4.9 / 5.0 (38 ratings)

How clear and staff-actionable was this system breakdown?