Quick revision
The short answer
The rate limiter protects the product but is not the product, so for most limits it should fail open, allowing requests when Redis is down or slow, and fail closed only for limits that protect money or fragile systems. We give rate-limit calls a timeout of a few milliseconds and a circuit breaker so a sick Redis adds almost no latency, keep a local fallback limiter in each gateway with a share of each limit, accept and document that counts may reset after a failover, and prove the behaviour with game days and alerts on fallback mode.
What to remember
In this answer, we saw that the outage came from gateway threads blocking for two seconds on a dependency that was failing over, not from Redis failing. The redesign fails open with a bounded local fallback for most limits and fails closed only where money or fragile systems are at stake, uses millisecond timeouts and a circuit breaker on a dedicated connection, documents that counters may reset after failover, and proves the behaviour with load tests, game days and an alert on fallback mode.
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 rate limiter protects the product but is not the product, so for most limits it should fail open, allowing requests when Redis is down or slow, and fail closed only for limits that protect money or fragile systems. We give rate-limit calls a timeout of a few milliseconds and a circuit breaker so a sick Redis adds almost no latency, keep a local fallback limiter in each gateway with a share of each limit, accept and document that counts may reset after a failover, and prove the behaviour with game days and alerts on fallback mode.
Why this question is asked
This incident is a classic example of a protective component turning into a single point of failure. Redis failed for 25 seconds, which should have been a non-event for an API platform, and instead every gateway thread blocked and the whole API went down. Interviewers ask this to see whether we think about failure modes of supporting systems. In this answer, we will see exactly why the outage happened, decide what the limiter should do when Redis fails, and then build the redesign: tight timeouts and a circuit breaker, a local fallback, honest expectations about failover, and testing.
1Why a 25-Second Failover Took the API Down
Sentinel needed 25 seconds to detect the failed primary and promote a replica. During that time, every request's rate-limit call waited for its 2-second timeout. A gateway with 200 worker threads handling 2,000 requests per second fills all 200 threads in a tenth of a second with requests waiting on Redis. New requests queue, then time out, and the API is effectively down, even though the services behind the gateway are perfectly healthy.
Notice that the cause is not that Redis failed. It is that the gateway let a dependency it calls on every request block for 2 seconds. Whatever we decide about allowing or rejecting, the waiting has to go.
5 messages in order. Play them, or step through them one at a time.
The backend was never called. Thread exhaustion did the damage.
2Decide: Fail Open or Fail Closed
When the limiter cannot get an answer, it has two choices. Failing open means allowing the request as if the limit was not reached. Failing closed means rejecting it. If we fail closed for everything, a Redis failure becomes a full outage by design, which is worse than what any customer could do by exceeding their limit for 30 seconds.
So for most limits, those that enforce fairness and plan quotas, we fail open. For a few, failing closed is right because what they protect is worth more than availability: login and password-reset attempts that stop credential stuffing, SMS or email sending that costs money per message, payout or transfer endpoints, and calls into a fragile downstream system that would collapse without the limit. Each limit gets an explicit, documented failure mode.
| Limit | When Redis is down | Why |
|---|---|---|
| Per-customer API plan quota | Fail open, local fallback | Brief overuse is cheaper than an outage |
| Fairness between tenants | Fail open, local fallback | Local share keeps abuse bounded |
| Login and password reset | Fail closed or strict local limit | Protects accounts from guessing |
| SMS, email, payouts | Fail closed | Each extra call costs real money |
| Fragile downstream system | Fail closed | Overload would cause a worse outage |
3Tight Timeouts and a Circuit Breaker
A rate-limit check on a healthy Redis in the same zone takes well under a millisecond. So its timeout should be a few milliseconds, say 5 to 10 ms, not 2 seconds, and it should use its own connection with its own timeout so other Redis uses are not affected. A circuit breaker, for example from Resilience4j, wraps the call: after a burst of failures it opens and stops calling Redis entirely for a few seconds, then lets a trial call through to see if Redis is back.
With this in place, during the 25-second failover each request loses at most a few milliseconds before the breaker opens, and almost nothing after it. The threads never pile up.
4A Local Fallback That Keeps Abuse Bounded
Failing open does not have to mean unlimited. Each gateway instance keeps an in-memory limiter, such as a token bucket per API key, that it uses only while Redis is unavailable. Its limit is the customer's limit divided by the number of gateway instances, with some slack: with 10 instances and a plan of 1,000 per minute, each instance allows about 150 per minute for that key. Because load balancers spread requests roughly evenly, the total stays close to the plan, and a single abusive client cannot get far beyond it.
The fallback is approximate, and that is fine for 30 seconds. We emit a metric and alert when gateways run in fallback mode, so people know limits are approximate for now.
5Accept What Failover Does to Counters
Redis replication is asynchronous. When a replica is promoted, the last few hundred milliseconds of counter updates may never have reached it, and keys written during the outage were written to local fallbacks instead. So after a failover some customers get a slightly fresh window. For rate limits that is usually acceptable, and it should be written down so nobody treats a few extra requests as a bug. Limits that bill customers should be counted from durable logs, not from these counters.
6Prove It Before the Next 03:10
A failure path that has never been exercised is a guess. We include Redis failures in load tests, killing the primary while traffic flows and checking that latency rises by milliseconds, not seconds, and that fallback limits hold. We repeat it in game days in production-like environments, and keep the fallback-mode alert wired to the on-call team.
7Follow-up questions
Which limits would you fail closed, and why?
The ones where one extra request causes real harm that is worse than unavailability: login and password-reset attempts, because an attacker could use the outage to guess passwords at full speed; sending SMS or email, because each message costs money and spam damages our sender reputation; payouts and transfers; and limits that shield a fragile downstream system such as a legacy core banking API. Even there, a strict local limit can replace a full rejection, so legitimate users are not locked out completely.
Why give the limiter its own Redis connection?
So that its very short timeout does not apply to other operations such as caching, and so that a pile-up in other Redis uses cannot delay rate-limit checks. Separate pools also make it easy to measure the limiter's latency on its own.
Could we make Redis itself more available instead?
Yes, and we should tune Sentinel's detection time or use a cluster with faster failover. But some failover time always remains, and Redis can be slow without being down, so the gateway still needs timeouts, a breaker and a fallback.
8Conclusion
In this answer, we saw that the outage came from gateway threads blocking for two seconds on a dependency that was failing over, not from Redis failing. The redesign fails open with a bounded local fallback for most limits and fails closed only where money or fragile systems are at stake, uses millisecond timeouts and a circuit breaker on a dedicated connection, documents that counters may reset after failover, and proves the behaviour with load tests, game days and an alert on fallback mode.
Open with
The limiter protects the product, but it is not the product, so a Redis failure should not take the API down. What hurt us was 2-second timeouts: during a 25-second failover every gateway thread blocked waiting on Redis, and thread exhaustion did the rest.
Then, if they want more
For most limits I would fail open, meaning allow the request, because rejecting everything turns a Redis failure into a full outage. I would fail closed only for limits that protect money or fragile systems, like SMS sending, payouts or login attempts.
Then I would give rate-limit calls their own connection with a timeout of a few milliseconds, and wrap them in a circuit breaker, so a slow or failed Redis costs almost no latency and is not called while unhealthy.
When Redis is unavailable, each gateway falls back to a local limiter with its share of each limit, the limit divided by the number of instances plus some slack, so abuse stays bounded. I would document that counts may reset or lose a few seconds after a failover, because replication is asynchronous, which is fine for rate limits.
And I would test it by killing the primary in load tests and game days, and alert when gateways run in fallback mode.
About this answer
- Last updated
- 13 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 "What should the rate limiter do when Redis is down or slow, and how would you redesign...": https://scrivio-interview-library.netlify.app/databases/redis-patterns/40c4f75243/