System design
Design a rate limiter
Design a rate limiter for a public REST API. Each API key may make 1,000 requests per minute. A request over the limit gets 429 Too Many Requests with a Retry-After header.
The API runs on many stateless servers behind a load balancer and peaks at about 50,000 requests a second.
Things to cover
- The algorithm: fixed window, sliding window or token bucket
- Where the limiter runs, and where the counts live
- Keeping counts consistent across servers
- What happens when the counter store is slow or down