1. Redis HA Deployment Modes
Standalone
Single pod. No HA. Good for dev/cache-only.
Primary + Replica
One master, N replicas. Read scaling. Manual failover.
Sentinel HA
Auto-failover via Sentinel quorum. Single shard.
Cluster Mode
Sharding + HA. 16384 slots across ≥3 primaries.
2. Redis Sentinel — Auto-Failover
Sentinel Process
Runs alongside Redis. Monitors master health, coordinates failover via quorum vote.
Quorum
Minimum Sentinels that must agree master is down before failover starts. Typical: 2 of 3.
Leader Election
Sentinels elect a leader among themselves. Leader picks the best replica to promote.
Client Discovery
Clients ask Sentinel for current master address — Sentinel is the source of truth.
Sentinel Topology in 3 Availability Zones
3. Redis Cluster Mode — Sharding + HA
Hash Slots
16384 slots distributed across primary shards. Each key hashes to a slot: CRC16(key) % 16384.
Gossip Protocol
Nodes exchange health/slot info via gossip every second. Failure detected by majority of nodes.
Auto Failover
Cluster built-in: when a primary fails, its replica is promoted automatically by cluster vote.
Min 6 Pods
Minimum viable cluster: 3 primaries (each owning ~5461 slots) each with 1 replica.
4. Kubernetes Patterns for Redis
StatefulSet — why not Deployment?
Stable Pod Names
redis-0, redis-1, redis-2 — always the same. Sentinel config can reference stable DNS.
Ordered Start/Stop
Redis 0 starts first (becomes master), replicas 1 & 2 start after and sync from master.
Persistent Volume per Pod
Each pod gets its own PVC via volumeClaimTemplates — data survives pod rescheduling.
Headless Service
clusterIP: None gives each pod a stable DNS: redis-0.redis.namespace.svc.cluster.local
Services Needed
Headless Service (StatefulSet DNS)
clusterIP: None — enables pod-to-pod DNS for replication and Sentinel discovery.
Master Service (for writes)
ClusterIP service pointing to current master. Updated dynamically by operator or Sentinel hook.
Replica Service (for reads)
Targets all replicas via label selector. Clients can distribute reads across replicas.
Zone-Aware Scheduling with topologySpreadConstraints
5. Multi-Zone Data Sync — How It Works
WAIT numreplicas timeout for semi-sync semantics when durability matters.
6. Replication Flow — FULLSYNC vs PSYNC
Replica sends PSYNC ? -1
Replica doesn't know master's replication ID yet. Asks for a full sync.
Master forks + creates RDB snapshot
Master forks a child process to dump current dataset to an RDB file. Parent continues serving clients.
Master sends FULLRESYNC + RDB
Sends replication ID and current offset, then streams the RDB file to the replica. New writes are buffered in replication backlog.
Replica loads RDB, then drains buffer
Replica flushes existing data, loads the RDB snapshot, then applies buffered commands that arrived during the RDB transfer.
Replica enters online replication mode
Now in sync. Master streams every write command to the replica in real-time.
Master maintains replication backlog
A circular buffer (default 1MB, tune with repl-backlog-size) holds recent commands. If replica lag stays within backlog size, partial sync is possible.
Every write is sent as RESP command
Master sends a stream of Redis commands (SET, HSET, ZADD…) to replicas. Replica applies them in order.
Replica tracks replication offset
Both master and replica maintain the current byte offset. If they match, replica is fully caught up.
REPLCONF ACK sent periodically
Replica sends its current offset to master every second. Master uses this for WAIT command and lag monitoring.
Replica reconnects, sends PSYNC <replid> <offset>
Replica remembers the master's replication ID and its last known offset.
Master checks if offset is still in backlog
If the replica's offset falls within the backlog window → CONTINUE (partial sync). If the backlog was overwritten → FULLRESYNC.
Partial sync (best case)
Master only sends the missing commands. Fast, low bandwidth — typically what happens after a brief network blip.
repl-backlog-size 64mb — for high-write-rate clusters or replicas in distant zones with occasional network gaps, a larger backlog avoids expensive full resyncs.
7. Multi-Cluster & Geo-Distributed Sync
Redis Enterprise Geo-Replication
Conflict-free Replicated Data Types (CRDTs). Each region is a primary that accepts writes. Conflicts resolved automatically. Requires Redis Enterprise license.
RedisGears / KeyDB
KeyDB (fork) supports multi-master async replication between clusters. Community alternative to Redis Enterprise for active-active.
Application-Level Fan-Out
App writes to multiple Redis clusters simultaneously. Simple but doubles write latency. Suitable for cache invalidation, not primary storage.
redis-shake / rump
Tools for one-way streaming replication between independent Redis instances/clusters. Used for migration, DR, and near-real-time cross-cluster sync.
8. K8s Operators for Redis
Redis Operator (Spotahome)
Manages Sentinel-based HA. Creates StatefulSets, Services, ConfigMaps automatically. Handles failover endpoint updates.
Redis Cluster Operator (OT-Container)
Manages Redis Cluster mode. Handles slot rebalancing, node addition/removal, TLS, password rotation.
Redis Enterprise Operator
Full lifecycle management of Redis Enterprise clusters. Supports geo-replication, Active-Active, module management, and enterprise security features.
Bitnami Redis Helm Chart
Helm chart that deploys Sentinel HA or standalone. Not a true operator but widely used. Add sentinel.enabled=true for HA mode.
9. Comparison: Deployment Modes
| Mode | HA? | Sharding? | Failover | Multi-Zone | Data Loss Risk | Complexity | Best For |
|---|---|---|---|---|---|---|---|
| Standalone | None | No | Manual | No | High | Low | Dev / ephemeral cache |
| Primary + Replica | Partial | No | Manual | With scheduling | Medium | Low | Read scaling + manual DR |
| Sentinel HA | Yes | No | Auto (~30s) | Yes (3 zones) | Low-medium | Medium | Single-shard HA, <100GB |
| Cluster Mode | Yes | Yes | Auto (<10s) | Yes (built-in) | Low-medium | High | Large datasets, >100GB, high throughput |
| Enterprise Geo | Yes | Yes | Auto | Multi-region | Very Low | Very High | Global apps, Active-Active |
10. Sentinel Failover — Step-by-Step Walkthrough
Master pod crashes (Zone A fails)
redis-master-0 stops responding. All 3 Sentinels stop receiving PING replies from port 6379.
Subjective Down (SDOWN) — each Sentinel marks master
After down-after-milliseconds (default 5s), each Sentinel independently marks master as SDOWN (Subjectively Down).
Objective Down (ODOWN) — quorum reached
Sentinels exchange SENTINEL IS-MASTER-DOWN-BY-ADDR messages. Once quorum (e.g. 2 of 3) agree → master is ODOWN (Objectively Down).
Leader Sentinel election
Sentinels elect a leader via Raft-like vote (first Sentinel to request gets votes, majority wins). Leader coordinates the failover.
Best replica selected
Leader picks replica with: (1) lowest slave-priority, (2) highest replication offset (most up to date), (3) lowest run ID as tiebreaker.
SLAVEOF NO ONE — new master
Leader Sentinel sends SLAVEOF NO ONE to the chosen replica (e.g. redis-replica-1 in Zone B). It promotes itself to master.
Other replicas reconfigured
Sentinels send SLAVEOF new-master-ip 6379 to remaining replicas. They resync from the new master.
Clients notified + service updated
Sentinels publish +switch-master event. Smart clients (Jedis, StackExchange.Redis, go-redis) listening to Sentinel automatically reconnect to new master. Operators update K8s Service selector.
Old master demoted (if it comes back)
When the original master pod recovers, Sentinel reconfigures it as a replica of the new master. Data is re-synced via PSYNC.
down-after-milliseconds lower (e.g. 2000ms) for faster detection, but beware false positives on network blips. Client reconnection adds another 1–5 seconds.