Your rate limiter runs in five regions with a cap of 100 requests a minute per user. One user gets 500 through. Where did the counting go wrong?
Global rate limiting fails when each region owns a local counter, because five regions each allowing 100 requests creates a 500-request ceiling. Use one atomic shared counter, route each user to an owning region, or lease regional budget deliberately. It also connects distributed counters to the point an interviewer is testing.
Answer
Short answer
A global rate limit cannot be enforced by five independent regional counters. Either every region mutates one shared atomic counter, requests for a user are routed to that user's owning region, or each region leases part of the global budget from a coordinator. Static per-region splitting is not equivalent; it under-limits users who stay in one region and still needs a story for failover and borrowing.
Was this answer helpful?
Likely follow-ups
- If you route each user's requests to one owning region, what happens to a user whose owning region is being drained for a deploy?
- How would you let a region borrow unused budget from the other four without a round trip on every request?
- Does a 429 you returned count against the user's own limit, and does a client retry count twice?
- Where would you put the limit if the expensive thing is not the request count but the size of the response?
Related questions
- You need to enforce 100 requests per minute per API key across a fleet of forty servers. Which limiting algorithm, and where does the counter live?hardAlso on rate-limiting and token-bucket8 min
- Your rate limiter has to work across twenty gateway instances. What does Redis do, and what breaks first?hardAlso on rate-limiting and redis5 min
- One tenant bursts to ten times their normal traffic and every other customer's latency doubles. Your global rate limit was never hit. How would you design for fairness instead?hardAlso on rate-limiting and token-bucket5 min
- Design a rate limiter that allows N requests per client per minute. Write the class.mediumAlso on rate-limiting and token-bucket4 min