Quick revision
The short answer
Most of the 38 seconds was detection: Sentinel waited the default 30 seconds of down-after-milliseconds before it even started, then spent a second or two electing a leader and promoting, and the clients needed a few more seconds to reconnect while commands in flight waited for their timeout. For planned work we never stop the primary; SENTINEL FAILOVER switches in seconds. For crashes we lower detection carefully, give services short command timeouts, retries for idempotent reads and a database fallback, and agree an objective we prove with drills.
What to remember
In this answer, we broke the 38 seconds into 30 seconds of default detection, one or two seconds of promotion and several seconds of client reconnection and waiting. We removed most of it for planned work with SENTINEL FAILOVER, lowered detection for crashes only as far as latency data allows, gave services short timeouts, fail-fast behaviour, a retry for idempotent reads and a database fallback, and agreed a realistic objective verified by drills under load.
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.
Most of the 38 seconds was detection: Sentinel waited the default 30 seconds of down-after-milliseconds before it even started, then spent a second or two electing a leader and promoting, and the clients needed a few more seconds to reconnect while commands in flight waited for their timeout. For planned work we never stop the primary; SENTINEL FAILOVER switches in seconds. For crashes we lower detection carefully, give services short command timeouts, retries for idempotent reads and a database fallback, and agree an objective we prove with drills.
Why this question is asked
A request like no more than 5 seconds of errors sounds like a tuning ticket, but it touches Sentinel settings, client libraries, every service's timeouts and the way the team does maintenance. The useful first move is to break the 38 seconds down, because each part has a different owner and a different fix. Interviewers ask this scenario to see whether we can do that, and whether we notice that the incident was planned maintenance, which should not cause a failover-shaped outage at all. In this answer, we will break down the timeline, fix planned maintenance, tune detection for crashes, change the services, and set an objective we can verify.
1Breaking Down the 38 Seconds
When the primary was stopped, its connections closed. Clients started reconnecting to the old address and failing, and Sentinels started counting. With the default down-after-milliseconds of 30 seconds, nothing happened for 30 seconds. Then the Sentinels agreed the primary was objectively down, elected a leader and promoted a replica, which usually takes one or two seconds. Finally each client had to notice: Lettuce reconnects with backoff, resolves the primary through Sentinel again, and only then can retry. Commands issued in the meantime either queued until reconnection or waited for the command timeout, which in Lettuce defaults to 60 seconds unless spring.data.redis.timeout is set.
| Phase | Typical time | Who controls it |
|---|---|---|
| Detection | 30 s (default) | Sentinel down-after-milliseconds |
| Election and promotion | 1 to 2 s | Sentinel, mostly fixed |
| Client reconnection | 2 to 6 s | Lettuce backoff, Sentinel lookup |
| Requests waiting | up to the command timeout | service configuration |
2Planned Work: Never Stop the Primary
The host replacement was planned, so there was no need to wait for detection at all. SENTINEL FAILOVER orders tells the Sentinels to promote a replica now, without requiring agreement that the primary is down. The switch takes a second or two, and the old primary is reconfigured as a replica. Only then do we stop it and replace the host.
This alone removes most errors from maintenance, because the 30 seconds of detection disappear. Writes in flight during the switch can still fail or, since replication is asynchronous, a few acknowledged writes may be lost, so the runbook checks that the replica's offset matches the primary's before triggering it.
3Crashes: Tuning Detection With Care
For a real crash, detection time is down-after-milliseconds, so lowering it to 3 to 5 seconds cuts most of the gap. The cost is false failovers. A long blocking command (KEYS on a large database, a big DEL), a pause of the host, or network jitter can make a healthy primary miss pings for a few seconds. Each false failover makes every client reconnect and can lose recent writes. So we look at latency data first: LATENCY HISTORY and the slow log show the longest stalls the primary really has. If the worst stalls are 800 ms, 5 seconds is a reasonable setting; if they reach 4 seconds, we fix those stalls before lowering it.
4What Changes in the Services
The services must not wait 60 seconds for a dead connection. We set a command timeout well below the request timeout, for example 500 ms in a service with a 2-second budget, and make Lettuce reject commands while disconnected instead of queueing them, so requests fail fast and can take another path.
- Service sends GET to Redistimeout 500 ms
- Reply within 500 ms?YesUse the cached valueNoCount the fallback
- Is the value needed from Redis?YesRetry once after reconnectingNoRead from the database
- Return the responseslower, not failed
4 steps in order. Play them, or step through them one at a time.
Idempotent reads can be retried once after a short pause, since the second attempt often lands on the new primary. Writes need more care and are retried only when they are idempotent. Where Redis is a cache, the fallback to the database turns a failover into slightly slower requests instead of errors, which matters more for the 5-second goal than any Sentinel setting.
5Agreeing an Objective and Proving It
A promise of 5 seconds for every kind of failure is not realistic with Sentinel. A fair objective is about 5 seconds of errors for planned switches, and 10 to 15 seconds for crashes, with cache paths degrading to slower responses instead of errors. We then verify it with repeated drills under production-like client load: trigger SENTINEL FAILOVER, kill the primary process, freeze the host, and measure the error window from the services' own metrics, not from Redis logs.
6Follow-up questions
How would you test this in staging?
Run all 25 services, or a representative set, against a staging Sentinel deployment with a load generator replaying realistic traffic. Then repeat three experiments many times: SENTINEL FAILOVER, killing the primary process, and freezing the primary's host or dropping its network with a fault-injection tool. For each run, record the error count and duration per service from the services' metrics. The test passes when the error window stays within the objective in, say, 19 of 20 runs.
Is the Redis FAILOVER command different from SENTINEL FAILOVER?
Yes. Redis 6.2 added a FAILOVER command for coordinated switches on a single primary-replica pair, which pauses writes until a replica has caught up. With Sentinel managing the deployment, SENTINEL FAILOVER is the command to use, so Sentinels stay in charge of the configuration.
Why not make Redis optional for writes as well?
Some writes can be dropped or deferred, such as view counters. Others, like rate-limit counters or locks, change behaviour if skipped, so each write path needs its own decision about failing open or failing closed.
7Conclusion
In this answer, we broke the 38 seconds into 30 seconds of default detection, one or two seconds of promotion and several seconds of client reconnection and waiting. We removed most of it for planned work with SENTINEL FAILOVER, lowered detection for crashes only as far as latency data allows, gave services short timeouts, fail-fast behaviour, a retry for idempotent reads and a database fallback, and agreed a realistic objective verified by drills under load.
Open with
I would first break the 38 seconds down. Thirty of them were detection, because down-after-milliseconds defaults to 30 seconds and Sentinel does nothing before it expires. Leader election and promotion took a second or two.
Then, if they want more
The rest was clients: Lettuce has to back off, ask Sentinel for the new primary and reconnect, and commands in flight wait for the command timeout, which is 60 seconds by default if nobody set it. The biggest fix is in the process: for planned work we never stop the primary.
We run SENTINEL FAILOVER first, which promotes a replica in a second or two without any detection delay, check that the old primary is now a replica, and only then replace the host.
For crashes I would lower down-after-milliseconds to around 3 to 5 seconds, but only after looking at latency history, because long blocking commands, host pauses or jitter would then trigger false failovers, and each one can lose writes.
In the services I would set the Redis timeout to around 500 milliseconds, well below the request timeout, fail fast while disconnected, retry idempotent reads once after reconnecting, and fall back to the database on cache paths so a failover means slower requests, not errors.
Finally I would agree a realistic objective with product, about 5 seconds for planned switches and 10 to 15 for crashes, and prove it with repeated drills under production-like load.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- Redis 6
- 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 "Where do the 38 seconds go, what can you realistically tune, and what do you change in...": https://scrivio-interview-library.netlify.app/databases/redis-scaling/3f928f62e3/