Pick the limit dimension first, usually the API key rather than the IP, then choose an algorithm: token bucket to allow bursts, sliding window for smoother enforcement. Keep counters in a shared store like Redis so every instance agrees, using atomic increments with expiry. Return 429 with a Retry After header and remaining quota, and fail open if the limiter itself is unavailable so it cannot take your API down.
Why interviewers ask this
This tests systems thinking in a small, bounded problem. The interviewer wants the distributed state issue named, because per instance counters do not enforce a global limit, plus an algorithm choice with a reason, correct HTTP semantics on rejection, and operational judgment about what happens when the counter store is down. It also reveals whether you think about the client's experience of being limited.
How to structure your answer
- Choose the key dimension and justify it.
- Pick an algorithm and say what behavior it produces.
- Explain how counters stay consistent across instances.
- Define the response and the limiter's own failure mode.
Example answer
I start with what I am limiting per, and for a public API that is the API key, not the IP, because customers behind one NAT should not knock each other out. Then the algorithm. Token bucket is my default, because it lets a client burst a little, which matches how real integrations behave: they wake up, fire twenty requests, then go quiet for an hour. A sliding window log is more precise but stores more per key. The important part is that the counter has to be shared, because if each of my six instances tracks its own count the real limit is six times what I advertised, so Redis with an atomic increment and an expiry, or a small Lua script when I need the check and the decrement together. On rejection I return 429 with Retry After and the remaining quota in headers, because a client that can back off properly stops hammering me. And I fail open, since a limiter that takes the API down has done more harm than the abuse it prevented.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How would you give one customer a temporary higher limit?
- What changes if you need the limit enforced at the edge?
- How would you rate limit expensive endpoints differently?
Related software engineer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions