System Design
10. API Design and ManagementAnimated
API Rate Limiting
Capping how many requests a client can make.
The idea
Protects the service from abuse and overload by rejecting requests over a quota.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- allowed
- rejected
4 requests arrive. The bucket refills 3 tokens per tick (max 9), so bursts are allowed until it empties. 4 pass.
- tick:
- 1
- allowed:
- 4
- rejected:
- 0
1/24
Bars show how many requests were let through each tick.
Step by step
- 1Identify the client
- 2Count requests
- 3Reject those over the limit with 429
- 4Return headers saying when to retry
Where it is used
Public APIs.
Watch out for
Pick the algorithm that matches burst needs.