Definition
- Redis Sentinel -- monitors one master plus replicas; a quorum of Sentinels promotes a replica on master failure; no sharding; data must fit on one node.
- Redis Cluster -- partitions the keyspace into 16384 hash slots across multiple masters;
CRC16(key) % 16384determines the slot; each master has replicas for HA. - Hash tags --
{SAV2001}:balanceand{SAV2001}:limitforce both keys into the same slot for multi-key operations. - Decision rule -- fits one node plus needs failover means Sentinel; exceeds one node plus needs sharding means Cluster.
Sentinel is a small branch of National Bank of India with one head cashier and standby cashiers, plus supervisors watching. If the head cashier faints, supervisors promote a standby. Cluster is a network of branches where account numbers are split into 16,384 buckets and each branch handles a range. The first question: how many customers and how much data? That decides one resilient branch or a sharded network.
Understanding the Concepts
What is Redis Sentinel?
Sentinel provides high availability for a single-node dataset. One master holds all data; replicas are full copies. Sentinel processes monitor the master via heartbeats and promote a replica by quorum when the master fails. The client asks Sentinels "who is master?" rather than hardcoding an address.
package com.bank.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
@Configuration
public class SentinelConfig {
@Bean
public LettuceConnectionFactory sentinelConnection() {
RedisSentinelConfiguration config = new RedisSentinelConfiguration()
.master("mymaster")
.sentinel("sentinel-1", 26379)
.sentinel("sentinel-2", 26379)
.sentinel("sentinel-3", 26379);
return new LettuceConnectionFactory(config);
}
}
Expected behavior:
Client connects to Sentinels, asks "who is master?"
Sentinels reply with the current master address.
If master fails, quorum promotes a replica automatically.
What is Redis Cluster?
Cluster shards data across multiple masters. Each key is mapped to a slot by CRC16(key) % 16384. Each master owns a range of slots and has replicas for failover.
package com.bank.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import java.util.List;
@Configuration
public class ClusterConfig {
@Bean
public LettuceConnectionFactory clusterConnection() {
RedisClusterConfiguration config = new RedisClusterConfiguration(
List.of("node-1:6379", "node-2:6379", "node-3:6379"));
config.setMaxRedirects(3);
return new LettuceConnectionFactory(config);
}
}
package com.bank.cache;
public class SlotCalculation {
public static void main(String[] args) {
// Cluster routes by slot
String key = "session:SAV2001";
// int slot = CRC16.hash(key) % 16384; // e.g. slot 8742 --> Master-B
System.out.println("Key '" + key + "' maps to a slot via CRC16 % 16384");
System.out.println("Cluster routes the request to the master owning that slot.");
}
}
Expected output:
Key 'session:SAV2001' maps to a slot via CRC16 % 16384
Cluster routes the request to the master owning that slot.
How do Sentinel and Cluster compare?
| Aspect | Sentinel | Cluster |
|---|---|---|
| Sharding | None (one master) | 16384 hash slots across masters |
| Data size | Must fit one node | Scales horizontally with masters |
| Write scaling | No | Yes |
| Read scaling | Yes (read from replicas) | Yes |
| Failover | Quorum of Sentinels | Per-shard (gossip among masters) |
| Multi-key ops | Always work | Only within same slot (use hash tags) |
| Minimum nodes | 1 master + replicas + 3 Sentinels | 3 masters + 3 replicas = 6 |
| Complexity | Lower | Higher |
package com.bank.cache;
public class TopologyDecision {
public static String decide(long dataGb, long qps) {
if (dataGb <= 25 && qps <= 100_000) {
return "SENTINEL: data fits one node, QPS within single-master capacity";
}
return "CLUSTER: data or QPS exceeds one node, needs horizontal sharding";
}
public static void main(String[] args) {
System.out.println(decide(10, 50_000)); // sessions, OTPs
System.out.println(decide(500, 500_000)); // market-data cache
}
}
Expected output:
SENTINEL: data fits one node, QPS within single-master capacity
CLUSTER: data or QPS exceeds one node, needs horizontal sharding
When do you use hash tags in Cluster?
Multi-key operations (MGET, MULTI/EXEC, Lua scripts touching multiple keys) only work when all keys land in the same slot. Hash tags force co-location by hashing only the content inside curly braces.
package com.bank.cache;
import org.springframework.data.redis.core.StringRedisTemplate;
public class HashTagExample {
private final StringRedisTemplate redis;
public HashTagExample(StringRedisTemplate redis) {
this.redis = redis;
}
public void demonstrateHashTags() {
// WRONG: keys for same account land on different slots
redis.opsForValue().set("balance:SAV2001", "150000");
redis.opsForValue().set("limit:SAV2001", "500000");
// MULTI/EXEC across these keys REJECTED in Cluster (different slots)
// CORRECT: hash tags force same slot
redis.opsForValue().set("{SAV2001}:balance", "150000");
redis.opsForValue().set("{SAV2001}:limit", "500000");
// Only {SAV2001} is hashed --> same slot --> MULTI/EXEC works
}
}
Expected behavior:
Without hash tags: CRC16("balance:SAV2001") and CRC16("limit:SAV2001") produce different slots
With hash tags: CRC16("SAV2001") used for both --> same slot --> multi-key ops work
When should you choose Sentinel?
Choose Sentinel for lightweight data that fits on one node: sessions, OTPs, tokens, rate-limit counters. The total dataset is small (under 25 GB), and the primary need is automatic failover, not horizontal scaling.
package com.bank.cache;
public class SentinelUseCase {
public static void main(String[] args) {
long users = 10_000_000;
long sessionSizeKb = 1;
long totalGb = (users * sessionSizeKb) / (1024 * 1024);
System.out.println("Session store: " + totalGb + " GB");
System.out.println("Fits one node --> use Sentinel for HA");
}
}
Expected output:
Session store: 9 GB
Fits one node --> use Sentinel for HA
When should you choose Cluster?
Choose Cluster when the data volume or request rate exceeds what one node can handle. Market-data caches, product catalogs with millions of items, and high-QPS read-heavy workloads are typical Cluster use cases.
package com.bank.cache;
public class ClusterUseCase {
public static void main(String[] args) {
long instruments = 50_000_000;
long priceSizeKb = 10;
long totalGb = (instruments * priceSizeKb) / (1024 * 1024);
long qps = 500_000;
System.out.println("Market-data cache: " + totalGb + " GB, " + qps + " QPS");
System.out.println("Exceeds one node --> use Cluster for sharding + HA");
}
}
Expected output:
Market-data cache: 476 GB, 500000 QPS
Exceeds one node --> use Cluster for sharding + HA
What are common mistakes?
The most common mistake is using Cluster just for HA when the data fits on one node, or forgetting hash tags in Cluster.
package com.bank.cache;
public class CommonMistakes {
public static void main(String[] args) {
// WRONG: using Cluster just for HA when data fits one node
// Sentinel already provides HA with less complexity and no hash-tag constraints
System.out.println("WRONG: 10 GB sessions on Cluster -- unnecessary complexity");
System.out.println("CORRECT: 10 GB sessions on Sentinel -- simpler, same HA");
// WRONG: forgetting hash tags in Cluster
System.out.println("WRONG: MGET balance:SAV2001, limit:SAV2001 -- different slots, rejected");
System.out.println("CORRECT: MGET {SAV2001}:balance, {SAV2001}:limit -- same slot, works");
}
}
Expected output:
WRONG: 10 GB sessions on Cluster -- unnecessary complexity
CORRECT: 10 GB sessions on Sentinel -- simpler, same HA
WRONG: MGET balance:SAV2001, limit:SAV2001 -- different slots, rejected
CORRECT: MGET {SAV2001}:balance, {SAV2001}:limit -- same slot, works
What should a senior engineer know?
- Sentinel favors availability over consistency (AP in CAP terms); during a network partition it may keep serving stale data.
- Cluster failover is per-shard; other shards keep serving while one shard fails over.
- Managed Redis offerings (AWS ElastiCache, Azure Cache) blur the Sentinel vs Cluster distinction but the same decision logic applies.
- Do not reach for Cluster merely for HA; reach for it when you need horizontal scale.
package com.bank.cache;
public class SeniorNuances {
public static void main(String[] args) {
System.out.println("Sentinel: AP (availability over consistency during partition)");
System.out.println("Cluster: per-shard failover, other shards unaffected");
System.out.println("Decision: data size + QPS determines topology, not HA alone");
}
}
Expected output:
Sentinel: AP (availability over consistency during partition)
Cluster: per-shard failover, other shards unaffected
Decision: data size + QPS determines topology, not HA alone
Visual Overview
Redis Sentinel
┌───────────┐ ┌───────────┐ ┌───────────┐
│ Sentinel-1│ │ Sentinel-2│ │ Sentinel-3│
└─────┬─────┘ └─────┬─────┘ └─────┬─────┘
│ monitor │ monitor │ monitor
▼ ▼ ▼
┌───────────┐ ┌───────────┐
│ Master │────►│ Replica-1 │ (full copy)
│ ALL data │ │ Replica-2 │
└───────────┘ └───────────┘
Quorum agrees master is down --> promote replica
Redis Cluster
Slot 0-5460 Slot 5461-10922 Slot 10923-16383
┌───────────┐ ┌───────────┐ ┌───────────┐
│ Master-A │ │ Master-B │ │ Master-C │
│ Replica-A │ │ Replica-B │ │ Replica-C │
└───────────┘ └───────────┘ └───────────┘
CRC16("{SAV2001}:balance") % 16384 = 8742 --> Master-B
Decision Tree
┌─────────────────────────────────────┐
│ Data fits one node? │
│ YES --> need HA? --> SENTINEL │
│ NO --> need sharding --> CLUSTER │
└─────────────────────────────────────┘
Key Takeaway
Redis Sentinel and Redis Cluster solve two different problems, so the first question is always what kind of data is in Redis and how much. Sentinel provides HA for a dataset that fits on one node: Sentinel processes monitor the master and promote a replica by quorum when it fails. It scales reads via replicas but not writes or memory beyond one machine, making it ideal for lightweight data like sessions, OTPs, and tokens.
Redis Cluster provides horizontal sharding and HA combined by splitting the keyspace into 16,384 hash slots across multiple masters. Both memory and write throughput scale with the number of masters. The constraint is that multi-key operations only work within the same slot, which is why you use hash tags like {SAV2001} to co-locate related keys.
At National Bank of India, the authentication team's sessions (10 GB) ran on Sentinel with three sentinels, while the pricing team's market-data cache (500 GB at high QPS) ran on Cluster. Pankaj used hash tags {SAV2001} so balance and limit for the same account landed in one slot.
Remember one sentence: Sentinel is HA for one node (fits-on-one-node data), Cluster is sharding plus HA for data that exceeds one node, and the first question is always what kind of data and how much.
---