Intermediate LevelSystem Design & Architecture
How does Redis Cluster shard data using Hash Slots?
β Interview Prompt: Explain Redis Cluster, 16,384 Hash Slots ($CRC16(key) \bmod 16384$), master-slave replication, cluster node failover, and hash tags.
Redis Cluster distributes data across multiple Redis nodes automatically using Hash Slots:
Architecture:
1
The keyspace is divided into 16,384 logical Hash Slots.
2
Key slot assignment formula: $\text{Slot} = \text{CRC16}(key) \pmod{16384}$.
3
Master nodes in the cluster own sub-ranges of the 16,384 slots.
4
Hash Tags: Enclosing part of a key in curly braces ('{user:100}:profile') forces related keys onto the exact same hash slot for multi-key operations!
Code Implementation Example
bash
# Inspecting Redis Cluster slot distribution via redis-cli:
redis-cli -c -h redis-node-1 CLUSTER SLOTSπ‘Inspecting Redis Cluster hash slot allocations via redis-cli.
π― Interview Key Takeaway
Redis Cluster uses 16,384 Hash Slots to shard data evenly across master nodes with automatic failover.
#System Design#Redis Cluster#Hash Slots#Distributed Caching#Intermediate
Back to all System Design & Architecture Questionsβ