Backend system design · about 40 minutes
Rate limiter for an API
Design the rate limiting of a public API. Each API key may make a set number of requests a minute, with different limits for free and paid plans, and a stricter limit on the login endpoint per IP address. The API runs on many servers. A blocked client must learn when it may try again, and the limiter must not become the reason the API is slow or down.
Ask first
- What is limited: per API key, per user, per IP, per endpoint, or a mix?
- Are short bursts allowed, or must requests be spread evenly?
- How exact must the limit be across servers: is a few percent over acceptable?
- If the limiter's store is down, do we let requests through or block them?
- Do limits change at run time, for example when a customer upgrades?
The outline
Write your own outline for each part first.
The strong answer, the pitfalls and the follow-ups opens with a year in the app. What a year includes