What is Rate Limiting
Limiting API request rate
Rate Limiting is a mechanism for limiting the number of requests to an API or service within a specific time period.
Why Rate Limiting Matters
- Protecting servers from overload
- Preventing DDoS attacks
- Fair resource distribution
- Infrastructure cost control
- Ensuring stable service for all users
Types of Limits
- Requests per second (RPS) — classic limit
- Requests per minute/hour — long-term control
- Per user — individual limits
- Per IP address — bot protection
- Per pricing plan — API monetization
Implementation Algorithms
- Token Bucket — tokens in a bucket
- Leaky Bucket — leaky bucket algorithm
- Fixed Window — fixed time windows
- Sliding Window — sliding window approach
HTTP Headers
- X-RateLimit-Limit — maximum requests
- X-RateLimit-Remaining — remaining requests
- X-RateLimit-Reset — limit reset time
- Retry-After — when to retry