Design a Rate Limiter
How the interviewer asks it
“Design a rate limiting service that sits in front of a public API and enforces per-client limits across many API servers.”
Want the full answer? Watch lesson 2 of the free system design course: a 23-minute video walkthrough of this question.
Typed drills are free and unlimited: the AI scores your answer against the outline below.
What the interviewer is looking for
- You compare algorithms: fixed window, sliding log, sliding window counter and token bucket, with their memory and burst behaviour.
- Where the limiter lives: gateway, sidecar or library, and why.
- How counters are shared across servers, and the race in read-then-write.
- What happens when the counter store is slow or down (fail open or fail closed, and why).
- Correct client responses: 429, Retry-After and limit headers.
How to structure your answer
- 01
Requirements
Limits per API key and per IP, different tiers, low added latency, accurate enough rather than perfect, limits changeable without deploys.
- 02
Algorithm
Pick a token bucket for burst tolerance or a sliding window counter for smooth limits; explain the trade-off.
- 03
Architecture
Check the limit in the API gateway against an in-memory store shared by all gateways, partitioned by client key.
- 04
Atomicity
Do the check-and-increment atomically in the store (a script or atomic increment with expiry) to avoid races.
- 05
Scale and failure
Local pre-counting for very hot clients, replication of the store, and an explicit fail-open policy with alerting.
- 06
Rules
Store limit rules in config, cache them in the gateway, and push updates.
Best answers from candidates
No candidate answers yet. Type yours, and if it scores 6 or more you can show it here without your name.
Answers are shared by candidates, without names, after a privacy check. Add yours
Common mistakes
- Keeping counters in each server's memory, so the real limit is multiplied by the number of servers.
- Choosing an algorithm without explaining what happens at window boundaries.
- Forgetting the client experience: no Retry-After, no headers.
Follow-up questions to expect
- Limits must hold across three regions.
- One customer wants a limit of 1 million requests a minute.
Now answer it out loud
Max will ask you this exact question, listen to your answer, push on the weak spots with follow-ups like the ones above, and score you when you finish.
Practice with MaxFree: a 5-minute voice round and unlimited typed drills, with scored feedback. No card, and your camera is never recorded.
More system design interview questions
Preparing for this round? Read how to practice for a system design interview.