Module Review: Clustering

[!NOTE] This module explores the core principles of Module Review: Clustering, deriving solutions from first principles and hardware constraints to build world-class, production-ready expertise.

1. Key Takeaways

  • Sharding: Data is split into 16,384 Hash Slots. Slot = CRC16(Key) % 16384.
  • Topology: Nodes use a P2P Gossip Protocol on a separate port (Client + 10000) to exchange state and detect failures.
  • Clients: Redis clients are “Smart”. They cache the slot map and route requests directly to the correct node.
  • Redirection:
  • MOVED: Permanent redirect (Slot ownership changed). Update cache.
  • ASK: Temporary redirect (Migration in progress). Do not update cache.
  • Failover: If a Master fails, its Replicas elect a new leader using a Raft-like consensus mechanism.

2. Flashcards

How many hash slots are in a Redis Cluster?
16,384
Which hashing algorithm determines the slot?
CRC16 modulo 16384
What is the Cluster Bus port?
Client Port + 10000 (e.g., 16379)
What is the difference between MOVED and ASK?
MOVED is permanent (update map). ASK is temporary (migrating).
How do you force multiple keys to the same slot?
Using Hash Tags (e.g., `{user:100}:profile`)
What triggers a Failover?
When a majority of Masters agree a node is FAIL.

3. Cheat Sheet

Concept Description
Hash Slot Bucket for data. 16k total.
Hash Tag {tag} forces keys to same slot.
Gossip Protocol for node communication.
PFAIL “Possible Fail” (I can’t reach you).
FAIL “Confirmed Fail” (Majority can’t reach you).
Epoch Cluster version number (logic clock).
MOVED Error: “Wrong node, go here permanently.”
ASK Error: “Migrating, ask there temporarily.”
MIGRATE Command to move keys atomically.

4. Next Steps

Now that you understand how Redis Cluster works, you are ready to learn about Caching patterns.

Redis Glossary