Database
NoSQL
Redis
High Availability & Clustering

High Availability & Clustering

Scaling Redis and ensuring it stays online during failures is a critical skill for backend engineers.

1. Replication (Master-Slave)

Replication allows data from one Redis server (Master) to be replicated to one or more servers (Slaves/Replicas).

  • Master: Handles both reads and writes.
  • Replica: Handles read-only operations (scales read performance).
# On Replica configuration
replicaof <master-ip> <master-port>

2. Redis Sentinel

Sentinel provides High Availability (HA) for Redis. It monitors your Master-Slave setup and automatically promotes a Replica to Master if the Master fails.

Functions of Sentinel:

  • Monitoring: Checks if master and replicas are working.
  • Notification: Notifies administrators/applications about failures.
  • Automatic Failover: Initiates failover if master is down.
  • Configuration Provider: Acts as the source of truth for clients to find the current Master.

3. Redis Cluster

While Sentinel provides HA, Redis Cluster provides Horizontal Scaling (Sharding).

  • Data Sharding: Data is automatically split across multiple Redis nodes.
  • Hash Slots: Redis uses 16,384 hash slots. Every key is mapped to a slot, and slots are distributed across nodes.
  • No Proxy: Clients connect directly to the nodes.

Cluster Topology:

  • At least 3 master nodes are required for a functional cluster.
  • Each master should have at least one replica.

4. Summary Table

FeatureSentinelCluster
Primary GoalHigh AvailabilityScalability + Availability
ShardingNo (All nodes have same data)Yes (Data is distributed)
Automatic FailoverYesYes
Node limitSmall setsUp to 1000 nodes
Client ComplexityLowHigher (Needs cluster-aware client)