Redis High Availability: Three Tiers from Replication to Cluster — Choose the Right Level
This article explains Redis high availability as a three-tier progression — master-slave replication for redundancy, Sentinel for automatic failover, and Cluster for sharding — detailing configuration, split-brain prevention, multi-key limitations, and a decision framework to avoid over-engineering.
Reading font
1. Master-Slave Replication: The Foundation
A single Redis instance has two inherent ceilings: failure means total outage and memory capacity cannot scale . Master-slave replication addresses the first by providing data redundancy.
# Replica redis.conf (5.0+ uses replicaof, not slaveof)
replicaof 192.168.1.10 6379
masterauth "Master@123" # Required if master has password
replica-read-only yes # Keep replica read-onlySynchronization occurs in two phases:
Initial: replica PSYNC → master BGSAVE full RDB → transfer → replica loads
Ongoing: master pushes write commands in real time (replication backlog buffers disconnect periods)Health check focuses on one field:
INFO replication
# master_link_status:up ← must be up
# master_repl_offset vs slave_repl_offset difference = bytes behindMaster-slave solves redundancy, not high availability. If the master fails, the replica does not promote automatically; manual REPLICAOF NO ONE is required, causing service interruption.
Another often-overlooked issue: replication lag . Writing to master then immediately reading from replica may return stale data. The fix mirrors MySQL: route read-after-write requests to the master .
2. Sentinel: Automating Failover
Sentinel runs as independent processes, at least 3 and odd-numbered , with three duties: monitor master, vote on objective down, elect new master and notify clients.
# sentinel.conf, one per Sentinel node
sentinel monitor mymaster 192.168.1.10 6379 2 # 2 = quorum for objective down
sentinel auth-pass mymaster Master@123
sentinel down-after-milliseconds mymaster 5000 # 5s no response = subjective down
sentinel failover-timeout mymaster 60000Failover chain:
Master unresponsive for 5s → each Sentinel marks subjective down .
Quorum reached → objective down confirmed.
One Sentinel elected leader to execute failover.
Replica with most complete data promoted to master.
Remaining replicas repoint to new master; clients receive new address.
Clients must connect to Sentinel, not hardcode master IP . Lettuce and Jedis support Sentinel mode to query current master.
Split-Brain: The Critical Pitfall
The most dangerous and easily ignored problem in Sentinel setups:
Master isolated by network partition (process alive, but Sentinels cannot reach)
→ Sentinels elect new master, service restored
→ Old master in isolated network continues accepting client writes
→ Partition heals, old master demoted to replica, full sync from new master
→ Writes accepted during isolation are completely lostData "appears written successfully" then vanishes silently, making post-mortem extremely difficult.
Mitigation requires two master settings:
min-replicas-to-write 1 # At least 1 replica online to accept writes
min-replicas-max-lag 10 # And replica lag ≤ 10 secondsThe isolated old master fails these checks and rejects writes — surfacing errors early is far better than silent data loss. If using Sentinel, these two settings are mandatory.
3. Cluster: Data Sharding
When single-node memory is insufficient (e.g., 50GB+) or write throughput exceeds one machine, Cluster shards keys across multiple master nodes using 16,384 hash slots .
# Minimum cluster: 3 masters + 3 replicas
redis-cli --cluster create \
192.168.1.10:6379 192.168.1.11:6379 192.168.1.12:6379 \
192.168.1.13:6379 192.168.1.14:6379 192.168.1.15:6379 \
--cluster-replicas 1
# Routing: key → CRC16(key) % 16384 → assigned master
# Client connects to any node, follows MOVED/ASK redirects automaticallyThe trade-offs — why "don't adopt until scale demands it":
Multi-key operations : MGET, transactions, pipelines only work on keys in the same slot; cross-slot returns CROSSSLOT error.
Lua scripts : All keys accessed must reside in the same slot.
Pub/Sub : Regular SUBSCRIBE broadcasts to entire cluster, overhead scales with node count; Redis 7.0+ introduces sharded SSUBSCRIBE.
Client support : Must speak cluster protocol; legacy clients and connection pools need replacement.
Operations : Slot migration, failure recovery, monitoring — all multi-node complexity.
Cross-slot workaround: hash tags — wrap the slot-determining portion in {}.
# These three keys hash only on user:1001, guaranteeing same slot
{user:1001}:profile
{user:1001}:orders
{user:1001}:cartDesign hash tags before deploying Cluster — far cheaper than rewriting code afterward.
4. Which Tier to Choose: A Decision Flow
What if data is lost?
├─ Don't care (pure cache, DB is source of truth)
│ → Single instance OK, master-slave for redundancy
└─ Painful (locks / sessions / counters)
├─ Memory < single-node capacity (10–20GB)
│ → Master-slave + Sentinel (3 nodes, odd)
└─ Memory or QPS exceeds single node
→ Cluster (3 master + 3 replica minimum)
└─ Heavy multi-key usage → design hash tags first, then adoptRule of thumb: Single instance ≤10GB memory, ≤100k QPS — Sentinel is fully sufficient. Most businesses never reach that scale yet adopt Cluster first, only to be bitten by CROSSSLOT and operational complexity.
5. The Final Layer Is Not Redis, But Business Degradation
Even perfect Redis HA can suffer total outage — network issues, misconfiguration, OOM, human error. Every tier must have a degradation plan:
Lock degradation : On Redis lock failure, fall back to DB optimistic lock or reject request.
Cache degradation : On Redis unavailability, query DB directly with rate limiting to protect DB (otherwise cache miss storms DB).
Core data : Relational DB remains system of record; Redis is an acceleration layer.
The ultimate HA layer is the application's ability to degrade, not Redis never failing.
6. Operational Command Cheatsheet
# Sentinel: view current master address
redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster
redis-cli -p 26379 SENTINEL master mymaster # includes config epoch
# Graceful master switch before maintenance (more controlled than waiting for auto-failover)
redis-cli -p 26379 SENTINEL failover mymaster
# Manual master-slave adjustment
redis-cli REPLICAOF NO ONE # Promote replica to master
redis-cli REPLICAOF 192.168.1.11 6379 # Repoint to new master
# Cluster
redis-cli --cluster info 192.168.1.10:6379
redis-cli --cluster reshard 192.168.1.10:6379 # Scale out by moving slots7. Checklist
Evolution path: master-slave (redundancy) → Sentinel (auto-failover) → Cluster (sharding) — upgrade on demand, avoid over-engineering .
Master-slave only provides redundancy; failover is manual; read-after-write goes to master to avoid lag.
Sentinel requires ≥3 odd nodes; quorum decides objective down; clients connect to Sentinel, not static IP.
With Sentinel, always configure min-replicas-to-write + min-replicas-max-lag to prevent split-brain.
Cluster restricts multi-key, Lua, pub/sub to same slot; {} hash tags must be planned at design stage.
Single instance ≤10GB / ≤100k QPS — Sentinel is enough.
Every tier needs a business degradation plan; Redis is never the sole source of truth.
For questions about attribution, corrections or content rights, please contactand we will review it promptly.
Published
AI-assisted summary