Home›Learn›Redis 3: high availability
Redis · Chapter 3

High availability: Sentinel and Redis Cluster

What happens to your app when the Redis box dies?

Why a cache needs high availability, how Sentinel and Cluster fail over, and the writes a failover can lose.

Chapter 3 · High availability

Why Redis needs high availability too

"It is only a cache" is true until the cache goes down at peak. Every request falls through to the main database at once, and the database that was sized for cache misses gets all of them.

What we protect

The main database behind the cache, and anything you keep only in Redis: sessions, carts, rate limits, queues.

The two options

Sentinel watches one master and its replicas and fails over. Redis Cluster splits keys across several masters, each with replicas.

What it can lose

Replication is asynchronous. A write the master acknowledged but had not copied is lost in a failover. Redis does not promise otherwise.

What still matters

Plan for a cold restart anyway: how long does the app take to warm the cache, and can the database survive it?

One master, watched

Sentinel: automatic failover for one master

Run at least three Sentinels, on boxes that fail independently. The quorum (set per master) decides when the master is considered down; a majority of Sentinels must still be able to talk before any failover starts. Clients ask Sentinel for the current master instead of hard-coding it.

Step through it:

# sentinel.conf on three separate hosts
sentinel monitor cache 10.0.0.11 6379 2
sentinel down-after-milliseconds cache 5000
sentinel failover-timeout cache 60000
# from a client or redis-cli:
SENTINEL get-master-addr-by-name cache
Many masters

Redis Cluster: split the keys, keep the replicas

When one master is not enough memory or throughput, Redis Cluster spreads the 16384 hash slots across masters. The usual minimum is three masters with one replica each, in different zones. A master that cannot reach a majority of masters for cluster-node-timeout stops accepting writes, which limits how long a cut-off master can take writes that will be lost.

Step through it:

Be honest about it

What a failover can lose, and how to narrow it

Sources: Redis Sentinel, Scale with Redis Cluster.

Next · chapter 4Running it as a DBREWhat I watch, the settings, the commands← Chapter 2: How it stores your data
Part 1 of 4 · Learn · 56 pagesAll pages

How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.

Start 1: the basicsStart 2: ten conceptsStart 3: how a query travelsStart 4: napkin mathThe courseShort videosPostgreSQL 1: why PostgreSQLPostgreSQL 2: how it stores your dataPostgreSQL 3: what happens on every writePostgreSQL 4: high availability with PatroniPostgreSQL 5: running it as a DBREPostgreSQL 6: when it breaksPostgreSQL on Kubernetes: CloudNativePGMySQL 1: why MySQLMySQL 2: how it stores your dataMySQL 3: what happens on every writeMySQL 4: high availability with InnoDB ClusterMySQL 5: running it as a DBREMySQL 6: when it breaksMySQL failover with OrchestratorMySQL on Kubernetes: the Percona operatorsMongoDB 1: why MongoDBMongoDB 2: how it stores your dataMongoDB 3: what happens on every writeMongoDB 4: high availability with replica setsMongoDB 5: running it as a DBREMongoDB 6: when it breaksMongoDB on Kubernetes: the Percona operatorB-tree and LSM treeRedis 1: why RedisRedis 2: how it stores your dataRedis 3: high availabilityRedis 4: running it as a DBRERedis 5: when it breaksCassandra 1: why CassandraCassandra 2: how it stores your dataCassandra 3: high availabilityCassandra 4: running it as a DBRECassandra 5: when it breaksVector databases 1: why vector searchVector databases 2: how it stores your dataVector databases 3: high availabilityVector databases 4: running it as a DBREVector databases 5: when it breaksDatabase familiesEngines side by sideQueries that look fine and are notLost updates and write skewMany servers 1: keep a copy runningMany servers 2: who is the leaderMany servers 3: CAP as settingsMany servers 4: unique IDsMany servers 5: split the dataMany servers 6: across servicesMany servers 7: a thousand databasesStaff path, zero to architect