Sentinel vs. Cluster

Difficulty: Advanced

Question

What is the difference between Redis Sentinel and Redis Cluster? When would you choose each?

Answer

Redis Sentinel provides high availability for a single primary with replicas: a group of Sentinel processes monitors the primary, agrees when it is down, promotes a replica, and tells clients the new address. Redis Cluster shards data across multiple primaries using 16,384 hash slots, and each primary has replicas with failover built in. Use Sentinel when your data fits on one machine and you just need failover; use Cluster when you need to scale memory or write throughput beyond one node.

How Sentinel works

  • Run at least three Sentinels on separate machines so a majority can still be formed when one fails.
  • Each Sentinel pings the primary. If one cannot reach it for down-after-milliseconds, it marks it subjectively down (SDOWN).
  • When quorum Sentinels agree, the primary is objectively down (ODOWN). A leader Sentinel is then elected (needs a majority of all Sentinels) and runs the failover: picks the best replica by priority and replication offset, sends REPLICAOF NO ONE, and repoints the others.
  • Clients connect to Sentinels and ask SENTINEL get-master-addr-by-name mymaster to discover the current primary.

How Cluster works

  • Each key maps to a slot: CRC16(key) mod 16384. Each primary owns a range of slots.
  • Nodes talk over a cluster bus (data port + 10000) using a gossip protocol and detect failures themselves; no separate Sentinel processes are needed.
  • If a client sends a command to the wrong node, it gets a MOVED redirect; during resharding it may get ASK. Cluster-aware clients cache the slot map.
  • Multi-key commands, transactions and Lua scripts need all keys in the same slot. Hash tags force this: {user:42}:cart and {user:42}:orders hash only user:42.
  • Cluster supports only database 0, and a minimum of three primaries is recommended.

Side-by-side

AspectSentinelCluster
Main goalHigh availabilityHorizontal scaling plus HA
Data distributionFull dataset on every nodeSplit across primaries by slot
Write scalingOne primary onlyOne primary per shard
Multi-key operationsAny keysSame slot only (CROSSSLOT error otherwise)
Extra processesSentinel daemonsNone
Client requirementSentinel-aware discoveryCluster-aware, handles redirects
Multiple databasesYesOnly DB 0

Shared limitations

  • Both use asynchronous replication, so a failover can lose writes the old primary acknowledged but had not yet sent to replicas. WAIT and min-replicas-to-write reduce, but do not remove, this window.
  • Network partitions can briefly leave an old primary accepting writes that are later discarded.

Choosing in practice

A session store of a few GB for a startup: one primary, two replicas, three Sentinels. A product cache or rate limiter for a Swiggy-scale app that needs hundreds of GB and very high write throughput: Cluster. Managed services (AWS ElastiCache, Azure Cache, Redis Cloud) offer both as "cluster mode disabled" and "cluster mode enabled".

Sentinel failover sequence. Sentinels must agree the primary is down before one of them is elected to promote a replica.
  1. Sentinel cannot reach the primary: No valid reply within down-after-milliseconds.
  2. Marks it subjectively down (SDOWN): One Sentinel's opinion only.
  3. Quorum agrees: objectively down: Configured quorum of Sentinels confirm.
  4. Leader Sentinel elected: Needs votes from a majority of Sentinels.
  5. Best replica promoted: Chosen by priority and replication offset.
  6. Clients rediscover the primary: Via get-master-addr-by-name or notifications.

Code examples

Minimal Sentinel config and creating a cluster

# sentinel.conf (run on 3 separate hosts)
sentinel monitor mymaster 10.0.0.1 6379 2   # quorum = 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000

# Ask a Sentinel where the primary is
redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster

# Create a 3-primary, 3-replica cluster (nodes started with cluster-enabled yes)
redis-cli --cluster create \
  10.0.0.1:6379 10.0.0.2:6379 10.0.0.3:6379 \
  10.0.0.4:6379 10.0.0.5:6379 10.0.0.6:6379 \
  --cluster-replicas 1

# Which slot does a key live in?
redis-cli -c CLUSTER KEYSLOT '{user:42}:cart'

Sentinel needs a monitor line with a quorum; Cluster nodes are joined with redis-cli --cluster and keys are routed by slot, with hash tags controlling co-location.

Key points

  • Sentinel = HA for one primary; Cluster = sharding across primaries with built-in HA.
  • Cluster has 16,384 slots; slot = CRC16(key) mod 16384.
  • Hash tags {...} put related keys in the same slot for multi-key operations.
  • Run at least 3 Sentinels; failover needs a quorum to detect and a majority to authorise.
  • Both rely on async replication, so failover can lose recent writes.

Common follow-up questions

  • What are MOVED and ASK redirections?
  • Why does Redis Cluster use 16,384 slots?
  • How would you run a multi-key transaction in Redis Cluster?
  • How can a network partition cause data loss during failover?

Interview tips

  • Summarise in one line first: Sentinel is availability, Cluster is scale plus availability.
  • Mention hash slots, hash tags and the CROSSSLOT limitation; these are the details that prove depth.
  • Acknowledge async replication data loss; it shows you understand the guarantees, not just the architecture.

Concepts covered

Redis Sentinel, Redis Cluster, Automatic Failover, Hash Slots, Sharding, Quorum

More Redis & Caching questions