Design a distributed rate limiter that sits in front of a public API. Each API key may make a fixed number of requests per window. Limits must hold even when traffic is spread across many gateway instances.
Functional requirements
Limit requests per API key per time window
Return HTTP 429 with a retry hint when limited
Support different limits per plan
Non-functional requirements
Adds under 5 ms to request latency
Limits are accurate within 1% across instances
The API keeps serving if the limiter degrades
Constraints and scale
50 000 requests per second at peak
1 million active API keys
Deployed in 3 regions
You will practise
Compare token bucket and sliding window
Share counters across instances
Decide between failing open and failing closed
Show 2 hints
Where does the counter live so all gateway instances see it?
What happens to traffic if the counter store is down?