Databases & Storage• 40 Min
Design a Distributed Caching System (Redis Architecture)
HARD
System Architecture DiagramInteractive Zoom

Design a Distributed Caching System (Redis Architecture)
Redis is an in-memory data structure store used as a distributed cache, message broker, and streaming engine. At scale, running single-node Redis creates single points of failure and memory bottlenecks, requiring distributed clustering architectures.
1. Redis High-Availability Architectures
Architecture 1: Redis Sentinel (Master-Replica Failover)
- A primary node handles writes and asynchronously replicates to one or more standby replicas.
- Sentinel Nodes: 3 or 5 independent Sentinel daemons monitor node health via heartbeats.
- Quorum Failover: If the master becomes unresponsive, Sentinels vote to promote the most up-to-date replica to master and reconfigure clients automatically.
Architecture 2: Redis Cluster (Horizontal Sharding)
- Distributes keys across up to 1,000 master nodes using 16,384 Hash Slots:
$$\text{slot} = \text{CRC16}(key) \pmod{16384}$$
- Clients cache the hash slot routing table. If a key is queried on the wrong node, the node responds with a
-MOVED <slot> <target_ip>redirection.
Key Architecture Trade-Offs & Decision Matrix
| Dimension | Strategy / Option A | Strategy / Option B | Trade-off & Recommendation |
|---|---|---|---|
| Consistency vs Availability | Strict ACID (Strong Consistency) | Eventual Consistency (BASE) | Use ACID for ledger & balances; use Eventual Consistency for read-heavy feeds. |
| Data Partitioning | Vertical Partitioning | Horizontal Sharding | Scale vertically until write IOPs saturate NVMe disks, then shard by entity ID. |
| Caching Layer | Cache-Aside (Lazy) | Write-Through | Cache-Aside minimizes cache memory footprint for long-tail query distributions. |
Prerequisites
- Consistent Hashing Basic
- TCP Networking
Caching Simulator
Simulate Cache-Aside logic. See how cache misses trigger database reads (slow) and populate cache, while writes invalidate entries.
Active Cache Store:
user_101:{"name":"Alice","tier":"premium"}
settings_global:{"theme":"dark","maintenance":false}
Simulation Logs
No events logged yet...