Scaling Redis and high availability
35 questions in 8 subtopics.
A single Redis instance is fast, but production systems need more: copies that survive a failure, more memory and throughput than one server offers, and clients that keep working while the topology changes underneath them. Redis answers with asynchronous replication, Sentinel for automatic failover, and Redis Cluster for sharding across hash slots. Each brings trade-offs that show up in incidents: replicas that serve stale reads, failovers that lose acknowledged writes, shards that run hot because of hash tags, and clients that keep talking to nodes that no longer exist. The questions cover replication, Sentinel, cluster slots and resharding, multi-key operations, durability settings, data loss during failover, the Java clients Lettuce, Jedis and Redisson, and Spring Data Redis with Spring Cache, from how each mechanism works to the decisions senior engineers make about them.
Replication and replica reads
Redis replicas receive the primary's write stream asynchronously, tracked by a replication ID and offset, with a backlog that allows partial resynchronisation after short disconnections. Understand when a full sync is needed and what it costs, how output buffer limits and backlog size interact, and why reading from replicas offloads the primary at the price of stale reads that break read-your-writes.
A Redis primary with two replicas serves a Spring Boot service. Replication is what lets replicas take over after a failure and serve reads, so it pays to know exactly what a replica receives and when.
How does Redis replication work from the moment a replica connects, what are the replication ID, the offset and the backlog for, and when does a replica need a full resynchronisation instead of a partial one?A 25 GB Redis primary takes about 12,000 writes per second. After a 30-second network blip its replica never gets back in sync: replication restarts every few minutes and the primary's host shows repeated fork activity.
The primary log keeps saying the replica's client was 'scheduled to be closed ASAP for overcoming of output buffer limits', and every retry starts another full sync. What loop is the replica stuck in, and how do you break it?A product service on Spring Boot with Lettuce reads stock levels and user carts from a Redis primary that runs at 80 percent CPU. A colleague proposes sending all reads to the two replicas with ReadFrom.REPLICA_PREFERRED.
Your company serves customers from three regions, each with its own Redis for sessions, carts and feature flags. Product wants a user's cart to follow them when traffic moves between regions, and a vendor offers active-active Redis built on conflict-free replicated data types.
As the senior technical leader, how do you decide between active-active replication, a single write region with cross-region replicas, and keeping regions independent?Sentinel failover
Sentinel is a separate set of processes that monitors a primary, agrees that it is down, elects a leader and promotes a replica, then tells clients the new address. Know the difference between quorum and majority, how replicas are chosen, why at least three Sentinels must sit in independent failure domains, and what decides how long a failover takes from the client's point of view.
Redis Sentinel watches a primary and its replicas, promotes a replica when the primary fails and tells clients where the new primary is. It is the usual high-availability setup when a dataset fits on one primary.
How do Sentinels decide that a primary is down and who runs the failover, how is the new primary chosen, and how do clients find it?A payments platform runs Redis with Sentinel across two data centres: the primary, one replica and two Sentinels in DC-A, and another replica with one Sentinel in DC-B. DC-A lost power for two hours.
No failover happened and every Redis call from DC-B's services failed for two hours. Why, and how would you place Sentinels and replicas instead?A platform team runs 40 Sentinel-managed Redis deployments on Kubernetes as StatefulSets. After a node drain, several deployments ended with Sentinels listing replicas that no longer exist, and some clients connected to a pod IP that now belonged to another service.
During a planned host replacement, a Sentinel-managed Redis primary was simply stopped and 25 Spring Boot services returned errors for 38 seconds. Product now asks that a primary failure costs no more than 5 seconds of errors.
Where do the 38 seconds go, what can you realistically tune, and what do you change in the services and in the maintenance process?Redis Cluster hash slots and resharding
Redis Cluster splits the keyspace into 16,384 hash slots spread over several primaries, each with replicas, and moves whole slots when nodes are added or removed. Understand how keys map to slots, how MOVED and ASK redirects work during migration, how failover needs a majority of primaries, and why big keys, zone placement and full-coverage settings decide whether resharding and failures stay quiet.
A Redis Cluster with three primaries, each with one replica, holds 90 GB. The team plans to add a fourth primary to get more memory and write capacity.
How are keys assigned to nodes, what exactly moves when the fourth primary is added, and what do clients notice while it happens?A Redis Cluster with five primaries and one replica each lost a primary and its replica together, because both had been placed on the same physical host and that host failed. Services using any key, not only keys on that shard, started failing.
Clients log 'CLUSTERDOWN The cluster is down' for every key. Why does losing one shard take everything down, and which settings and placement rules change that?A rebalance of a six-primary cluster stopped halfway. redis-cli --cluster check now warns that a node has slots in migrating state, the rebalance output ended with an IOERR from MIGRATE, and latency on two shards spiked to 900 ms while it ran.
What most likely failed, how do you bring the cluster back to a clean state, and how do you rerun the migration safely?A team runs a Redis Cluster of six primaries and six replicas across three availability zones in one cloud region. A zone outage took the cluster down for 20 minutes even though half of the nodes were still healthy.
How does Redis Cluster decide to fail over, why can a single-zone loss stop it, and how would you lay out and size the cluster so it survives losing any one zone?A personalisation team stores user feature vectors and counters in Redis Cluster. The dataset grew from 800 GB to 4 TB in a year and is forecast to reach 10 TB, with 150 shards and a memory bill that now exceeds the team's compute costs.
As the senior technical leader, how do you decide whether to keep scaling Redis Cluster, adopt tiered storage, or move part of the data elsewhere?Multi-key operations and hash tags
In Redis Cluster a command, transaction or script can only touch keys in one slot, and hash tags in braces let related keys share a slot. Learn how clients split some multi-key commands per slot and lose atomicity, how to choose hash tags at the narrowest unit of atomic work, and why tags that are too broad concentrate load on a single shard.
A service using Lettuce's cluster client calls MGET with 200 keys and DEL with 50 keys spread over many slots. Both work, although the Redis documentation says multi-key commands need all keys in one slot.
Why do these calls work, what is the client doing behind the scenes, and which guarantees are lost compared with a single Redis instance?A shopping cart service is moving from a single Redis to Redis Cluster. Each cart is stored as two hashes, cart:42:items and cart:42:meta, which are updated together in a MULTI/EXEC block.
The update now fails with CROSSSLOT. Show how to rename the keys with a hash tag so the atomic update works, and explain what the braces do and how to avoid misusing them.A multi-tenant SaaS keeps per-tenant data in Redis Cluster with keys such as {t:9001}:user:17, so all of a tenant's keys can be used together. One shard now runs at 95 percent CPU and 80 percent memory while the other eleven stay under 30 percent.
What did the key design cause, how do you confirm it, and how do you redesign without losing the multi-key operations that really matter?A gaming platform keeps in-game credit wallets in Redis Cluster, one key per player, for 40 million players. A new feature lets players gift credits to each other, and a transfer must never create or destroy credits.
The two players' keys sit in different slots, so one Lua script cannot update both. How would you design the transfer, and where should the source of truth for balances live?Durability trade-offs in production
Redis keeps data in memory and persists it with RDB snapshots and an append-only file whose fsync policy decides how much a crash can lose. Know what appendfsync always, everysec and no really guarantee, how slow disks stall the main thread, what WAITAOF adds, and why a primary without persistence must never restart automatically while replicas follow it.
To speed up a busy Redis primary, a team turned off both RDB and AOF on it and kept persistence only on its two replicas. A process supervisor restarts the primary automatically whenever it exits.
The primary crashed at night and was back within two seconds. What happened to the data on all three nodes, and how should the setup be configured instead?A team runs Redis with AOF and appendfsync everysec for order drafts and states that they can lose at most one second of writes in a crash. Redis 7.2 also added the WAITAOF command.
What does everysec actually guarantee, how can it lose more than a second, and what do WAITAOF and the multi-part AOF of Redis 7 change?A Redis 7 primary with AOF everysec runs on a cloud VM whose disk it shares with application logs. Every few minutes p99 latency jumps from 1 ms to over a second, and the Redis log shows 'Asynchronous AOF fsync is taking too long (disk is busy?)'.
Explain the link between this log line and the latency spikes, and give the fixes in order of preference with their trade-offs.A fintech product team wants to keep customer wallet balances in Redis as the only store, to get single-digit millisecond writes. They point to a managed Redis-compatible service that advertises multi-zone durability and promise zero data loss.
As the senior technical leader, how do you evaluate whether any Redis-based setup can meet the requirement, and what decision and conditions would you set?Data loss during failover
Because replication is asynchronous, a primary can acknowledge writes that no replica has received, and a failover or network partition can discard them. Understand the size of that window, how split-brain loses writes on the isolated side, what WAIT and min-replicas-to-write limit, and why flows that must never lose a write need a durable source of truth.
A service writes to a Redis primary and gets OK, and moments later the primary fails and a replica is promoted. Teams are often surprised to find that the write is gone.
Why can an acknowledged write disappear after a failover with Sentinel or Redis Cluster, how large is the window, and what reduces it?A Spring Boot service stores one-time payment tokens in Redis through Lettuce. The team wants each token write to reach at least one replica before replying to the caller, to make loss on failover less likely.
Show how to issue WAIT after the write with Lettuce or Spring Data Redis, and explain what the result tells you and what it does not guarantee.An order-status cache and work queue run on Redis with Sentinel. A 40-second network partition isolated the primary together with two of six application servers; Sentinel promoted a replica on the other side, and when the partition healed, the old primary rejoined as a replica.
About 1,800 status updates written during the partition are gone. Explain exactly where they went, and which settings and application changes would have limited the loss.A payments service stored idempotency keys and per-card rate-limit counters only in Redis Cluster. A primary failed, the promoted replica was about 4 seconds behind, and 37 card charges were processed twice when clients retried.
You lead the follow-up across the three teams involved. What do you change in the design, and what rules do you set for Redis in payment flows?After several incidents, a risk review asks whether any business-critical flow in your 200 services silently depends on Redis never losing a write, through locks, deduplication keys, counters or queues.
As the senior technical leader, how do you find these dependencies, decide what must change, and keep new ones from appearing?Lettuce, Jedis and Redisson clients
Lettuce shares thread-safe Netty connections, Jedis lends blocking connections from a pool, and Redisson adds distributed objects such as locks and local cached maps. Know how each behaves under load and failure, which settings control timeouts, keepalive, pool size and cluster topology refresh, and why client configuration causes a large share of Redis incidents.
Java services can talk to Redis through Lettuce, Jedis or Redisson. Spring Boot uses Lettuce by default, but teams often add the others for specific features.
Compare the three clients' connection and threading models and their feature focus, and say when you would pick each.A Spring Boot MVC service with 200 Tomcat threads uses Jedis through Spring Data Redis with default pool settings. Under a load test, requests fail with 'Could not get a resource from the pool' while Redis CPU stays at 15 percent.
What is the bottleneck, and how do you size and configure the pool?A Redis Cluster was scaled from six to nine primaries during the day. Afterwards one Spring Boot service using Lettuce showed a steady stream of MOVED redirects in its metrics, higher latency, and some errors saying a connection point is not known in the cluster view.
What is wrong with this service's client configuration, and how do you configure it for a cluster that changes?In a cloud deployment, a Redis node's VM was replaced without the old machine sending any TCP reset. One Spring Boot service using Lettuce failed every Redis call with RedisCommandTimeoutException for about 15 minutes, while other services recovered in seconds.
Across 150 Java services, teams use Lettuce, Jedis and Redisson in many versions, with different timeouts, retry settings and serializers. Three of last year's Redis incidents were caused by client misconfiguration.
As the senior technical leader, would you standardise on one client, and how would you make good client behaviour the default without blocking teams that need special features?Spring Data Redis and Spring Cache
Spring Data Redis wraps the clients with RedisTemplate, repositories and a cache manager used by Spring's caching annotations. Understand how the cache manager lays out and clears keys, how repositories store entities and secondary indexes, which features change or stop working on Redis Cluster, and how to migrate many Spring services to a new topology safely.
A Spring Boot service that uses RedisTemplate, @Cacheable with RedisCacheManager and a message listener is moving from a single Redis instance to Redis Cluster. Configuration changes from spring.data.redis.host to spring.data.redis.cluster.nodes.
A team stores device sessions with Spring Data Redis repositories: an @RedisHash class with an @Indexed userId and a @TimeToLive field. Months later Redis memory keeps growing although live sessions are stable, and the set of all session ids is ten times larger than the number of live sessions.
A catalogue service runs @CacheEvict(cacheNames = "products", allEntries = true) after each nightly import. The products cache in Redis holds about 3 million keys, and at every import Redis stops answering for 2 to 4 seconds and other services time out.
A platform must move 40 Spring Boot services from a Sentinel-managed Redis to Redis Cluster within a quarter, because the single primary has reached its memory and CPU limits. The services use RedisTemplate, Spring Cache, Spring Session and a few Lua scripts.