API rate limiting is a policy that controls how frequently requests are accepted over time. It defines a scope, an allowance or replenishment rate, and rules for measuring time and handling excess traffic. Providers use it to reduce overload and abuse, support fairer resource sharing, and help maintain responsiveness. Unlike a concurrency limit, it controls requests over time rather than simply counting requests currently in progress.
How API Rate Limiting Works
For each incoming request, the limiter identifies the relevant scope, such as an API key, user, account, IP address, endpoint, or shared service budget. It checks recent usage or available allowance, admits requests within policy, and updates its records. Excess requests may be rejected or delayed, depending on the implementation.
API rate limiting can combine client-specific allowances with broader service limits. A client may therefore exhaust an endpoint's allowance while still having capacity elsewhere. The term “throttling” overlaps with rate limiting; the important distinction is whether traffic is rejected, queued, or paced.
Time Windows and Burst Allowances
A fixed window renews its allowance at set boundaries. In a hypothetical policy allowing 100 requests per minute, 100 requests just before a boundary and another 100 just after it could be accepted close together. Sliding-window approaches measure usage over a moving interval instead. Their accounting methods and burst behavior differ; they do not necessarily space requests evenly.
A token bucket replenishes a bounded allowance over time. Accumulated tokens permit bursts, while the replenishment rate constrains sustained traffic. A queue-based leaky bucket instead releases queued work steadily and rejects or drops excess work when its queue fills. For API rate limiting, the algorithm determines both whether a burst is accepted and when more capacity becomes available; not every limiter resets at a fixed clock boundary.
Advertisement — FinchTrade.
FinchTrade services
Get startedResponding to Exceeded Limits
HTTP 429 Too Many Requests commonly signals that a rate limit has been exceeded, but implementations can use other responses or drop connections. An optional Retry-After header indicates how long to wait, either as a number of seconds or an HTTP date. Remaining-budget and reset headers must be interpreted using the provider's documentation rather than assumed to have universal availability or meaning. For example, GitHub documents X-RateLimit-Reset as a reset time expressed in UTC epoch seconds; that interpretation should not be assumed for every API.
When API rate limiting interrupts requests, consult the provider's documentation and response guidance before retrying. Pace subsequent requests, reduce avoidable calls, and wait as directed rather than retrying immediately. If automatic retries are appropriate, use bounded backoff when guidance does not specify a delay. Before repeating an operation, check whether doing so could duplicate its effects, particularly when the original outcome is uncertain.
Policy Configuration and Limitations
Effective API rate limiting reflects backend capacity, request cost, and legitimate usage. Different endpoints or clients may warrant different allowances, including planned burst capacity. Providers should publish understandable limits and exceeded-limit behavior, then monitor traffic, rejection rates, and responsiveness to adjust configuration.
Enforcing a shared budget across multiple servers is harder than maintaining a local counter because usage must be coordinated; some implementations enforce approximate ceilings. Ordinary counting policies do not distinguish necessary requests from malicious ones, and rate limiting is not comprehensive DDoS protection. Limits set too low can obstruct valid clients, while permissive limits may provide insufficient protection.