Handbooks / REST API Design / Chapter 5
Rate Limiting and Idempotency
7 pages · ~5 min✓ Reviewed
Builds on Versioning and Pagination.
Rate Limiting Mental Model
1. What It Does
- Rate limiting caps requests per client per time window
- Excess requests are rejected or delayed
- Protects the server and enforces fairness
2. Key and Knobs
| Limit key | Shares one budget across |
|---|---|
| API key | one client app |
| User ID | one account |
| IP address | everyone behind one NAT |
| Route | one endpoint |
- Sustained rate: requests per second, long-run
- Burst size: how many can arrive at once
3. Where It Runs
| Server-side | Client-side | |
|---|---|---|
| Protects | the service | your own quota |
| Goal | reject excess | stay under provider limit |
bash
INCR rl:user42:minute_28
EXPIRE rl:user42:minute_28 60shared atomic counter in Redis (or one Lua script)