Quick revision
The short answer
The service is pointed at a fixed host, the old primary, instead of asking Sentinel which node is primary now, or it holds connections that were never re-resolved after the failover. After the failover that host is a replica, so every write gets READONLY until something reconnects. The fix is to configure Spring Boot with spring.data.redis.sentinel.master and spring.data.redis.sentinel.nodes so Lettuce discovers the primary through Sentinel, keep sensible timeouts, remove DNS or load balancer layers that hide the change, check the Sentinel quorum setup, and rehearse failover with SENTINEL FAILOVER.
What to remember
In this answer, we saw that Sentinel promotes a replica but does not move traffic: clients must ask it for the primary. A service configured with a fixed host keeps writing to the demoted node and gets READONLY until it reconnects by luck. Configuring spring.data.redis.sentinel.master and nodes, with timeouts, fixes it, as long as no DNS name or load balancer hides the change. A correct Sentinel quorum on three independent hosts and a regular SENTINEL FAILOVER test complete the setup.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The service is pointed at a fixed host, the old primary, instead of asking Sentinel which node is primary now, or it holds connections that were never re-resolved after the failover. After the failover that host is a replica, so every write gets READONLY until something reconnects. The fix is to configure Spring Boot with spring.data.redis.sentinel.master and spring.data.redis.sentinel.nodes so Lettuce discovers the primary through Sentinel, keep sensible timeouts, remove DNS or load balancer layers that hide the change, check the Sentinel quorum setup, and rehearse failover with SENTINEL FAILOVER.
Why this question is asked
Failover is supposed to be the moment high availability pays off. When a service instead fails for several minutes after a failover, the outage is longer than if there had been no replica at all, and the logs point at Redis even though Redis did exactly what it was told. Interviewers like this question because the fix is a few lines of configuration, but finding it requires knowing how Sentinel and the client cooperate. In this answer, we will recap what Sentinel does, see why the error appears, fix the Spring Boot configuration, look at the hidden layers that cause the same symptom, and check the Sentinel setup and a way to test it.
1A Quick Recap of Sentinel
Redis Sentinel is a separate process, normally three or more of them, that watches a primary and its replicas. When enough Sentinels agree that the primary is down, they promote a replica, reconfigure the other replicas to follow it, and tell the old primary to become a replica when it returns. Sentinel does not proxy traffic. Clients must ask Sentinel which node is the current primary for a named group, such as mymaster, and connect there themselves.
So Sentinel only helps clients that ask. A client that connects to redis-a.internal:6379 directly is unaware that Sentinel exists, and a failover changes nothing for it.
2Why the Writes Fail With READONLY
Let us look at the broken configuration, which is the most common cause.
5 messages in order. Play them, or step through them one at a time.
The client never asked Sentinel, so it never learned about redis-b.
Notice what happened. Lettuce kept its connection, or reconnected to the same host when the old primary came back. Since replicas are read-only by default (replica-read-only yes), every write fails. Reads still succeed, which makes the problem confusing: the service is half working. The errors last until the pods restart, or until the connection breaks for some other reason and the client happens to land on the right node, which explains the several minutes.
Even with Sentinel configured, the same symptom appears if connections are pinned and never re-resolved, for example a custom LettuceConnectionFactory built with a standalone configuration, or a pool of long-lived connections created before the failover that the client does not drop.
3Configuring Spring Boot to Use Sentinel
The fix is to give Spring Boot the Sentinel addresses and the group name instead of a host. Spring Boot then builds a RedisSentinelConfiguration, and Lettuce asks the Sentinels for the primary on connect and subscribes to their notifications of a primary switch.
With this in place, after a failover Lettuce reconnects, asks Sentinel again, and gets redis-b. The error window shrinks to the failover itself plus a reconnect, usually a few seconds. The timeouts matter: with no command timeout, requests hang on a dead socket instead of failing fast and triggering a reconnect.
If we want reads from replicas, we can add a LettuceClientConfigurationBuilderCustomizer that sets ReadFrom.REPLICA_PREFERRED. Writes always go to the primary Lettuce discovered.
4Layers That Hide the Topology Change
Sometimes the configuration looks right and the symptom remains. The usual cause is a layer between the client and Redis. A DNS name like redis-primary.internal that someone updates after failover is cached by the JVM and by resolvers, sometimes for minutes. A TCP load balancer in front of all three nodes can keep sending a connection to the demoted node. In Kubernetes, a Service that selects all Redis pods spreads connections to replicas.
So the rule is: let Lettuce talk to the Sentinels and to the Redis nodes by their real addresses. The addresses Sentinel announces must be reachable from the pods; if nodes run behind NAT or in containers, set replica-announce-ip and sentinel announce-ip so Sentinel reports addresses the client can use.
5Checking the Sentinel Setup and Testing Failover
A failover that takes too long or happens too eagerly also looks like a client problem. down-after-milliseconds decides how long a primary must be unreachable before a Sentinel considers it down, commonly 5,000 to 30,000 ms. quorum is how many Sentinels must agree it is down; the actual failover also needs a majority of Sentinels to authorise a leader. With three Sentinels and quorum 2, losing one Sentinel is fine. If all three run on the same host as the primary, losing that host loses both, so Sentinels must run on at least three independent hosts or zones.
Finally, we prove it works. In a staging environment we run SENTINEL FAILOVER mymaster while a load test writes continuously, and record how long writes fail. A test like this, run in CI with Testcontainers or as a regular chaos exercise, catches the configuration regression before production does.
6Follow-up questions
When would you choose Redis Cluster over Sentinel?
Sentinel gives high availability for one primary, so the whole dataset and write load must fit on one machine. When the data outgrows a node's memory, or writes outgrow one CPU core, Cluster shards slots across several primaries and also handles failover itself, without separate Sentinel processes. The cost is the cluster rules: multi-key operations only within a slot, no SELECT, and a cluster-aware client. For a few gigabytes and moderate load, Sentinel is simpler.
Why do reads keep working while writes fail?
The demoted node is a healthy replica with almost all the data, and replicas accept reads. Only writes are rejected. That partial failure is why the problem often goes unnoticed until users report lost carts, and why monitoring should count READONLY errors specifically.
Should the application retry READONLY errors?
A short retry with backoff can cover the failover itself, but it does not fix a client pointed at the wrong node, it only hides it. The real fix is Sentinel discovery; retries are an extra layer on top.
7Conclusion
In this answer, we saw that Sentinel promotes a replica but does not move traffic: clients must ask it for the primary. A service configured with a fixed host keeps writing to the demoted node and gets READONLY until it reconnects by luck. Configuring spring.data.redis.sentinel.master and nodes, with timeouts, fixes it, as long as no DNS name or load balancer hides the change. A correct Sentinel quorum on three independent hosts and a regular SENTINEL FAILOVER test complete the setup.
Open with
READONLY after a failover means the client is still talking to the old primary, which Sentinel has turned into a replica. Sentinel does not proxy traffic; clients have to ask it which node is primary.
Then, if they want more
My first suspicion is that the service is configured with spring.data.redis.host pointing at a fixed node, or with a custom standalone connection factory, so Lettuce never asks Sentinel and keeps or re-establishes connections to the same host. Reads still work because replicas serve reads, which is why it looks half healthy.
The fix is to remove the host setting and configure spring.data.redis.sentinel.master and spring.data.redis.sentinel.nodes with all three Sentinels, plus a command timeout and connect timeout, so Lettuce discovers the primary and reconnects to the new one after a switch.
I would also check that no DNS alias, load balancer or Kubernetes service sits in between and hides the change, and that Sentinel announces addresses the pods can reach. Then I would review Sentinel itself: at least three Sentinels on independent hosts, quorum 2, and a down-after-milliseconds that fits our tolerance.
Finally I would add a staging test that runs SENTINEL FAILOVER under load and measures the write error window, so we know it stays at a few seconds.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Redis documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "After a Redis Sentinel failover, a Spring Boot service using Lettuce keeps writing to...": https://scrivio-interview-library.netlify.app/databases/redis/6e8dacc9ac/