API rate limiting controls how frequently a client can use an API within a defined period. It protects shared capacity, makes access more predictable and gives service owners a way to manage bursts. A useful policy defines who is limited, which operations count and what a client should do after a limit is reached.
What is API rate limiting?
API rate limiting is a rule that caps how many requests a client, account, user or other identity may make during a stated time window. When the allowance is exceeded, the server can delay or reject additional work. The policy should explain the limit, scope and recovery signal.
A rate limit is not the same as a monthly quota. A rate limit controls short-term request frequency, while a quota commonly caps total usage over a longer period. An API may apply both, along with concurrency limits or endpoint-specific cost rules.
How is rate limiting different from throttling?
Rate limiting defines the permitted request rate, while throttling is the enforcement action that slows or rejects traffic when it exceeds a target. Teams sometimes use the terms interchangeably, but separating policy from enforcement makes API documentation and monitoring easier to understand.
For example, a service might permit an average of 60 requests per minute and return HTTP 429 when a client crosses the threshold. A gateway may also queue or delay excess work instead of rejecting it. Exact behaviour depends on the platform and configuration.
Which API rate-limiting algorithm should you choose?
Choose the algorithm according to traffic pattern, fairness, burst tolerance and the state available for counters. Fixed windows are simple, sliding windows smooth boundary effects, token buckets permit controlled bursts and leaky buckets shape traffic into a steadier queue. Test the selected method against real bursts and traffic boundaries.
| Algorithm | How it works | Useful when | Main trade-off |
|---|---|---|---|
| Fixed window | Counts requests in fixed intervals such as each minute. | Simple internal APIs or basic limits. | Requests at adjacent window boundaries can create a burst. |
| Sliding window | Counts or estimates requests over a moving interval. | Fairer rolling limits. | More state or calculation than a basic fixed counter. |
| Token bucket | Tokens refill at a steady rate up to a maximum; each request consumes tokens. | Short bursts are acceptable but long-term average must be controlled. | Capacity and refill rate must reflect actual system tolerance. |
| Leaky bucket | Requests enter a queue that drains at a configured rate. | Workloads that benefit from smoother processing. | Queueing adds latency and requires a rule for a full queue. |
Amazon API Gateway documents its throttling controls as best-effort targets rather than guaranteed request ceilings. Rate limits are therefore an operational control, not a replacement for capacity planning, timeouts, concurrency controls or protection against expensive requests.
How should you set a fair API rate limit?
Start with measured service capacity and the cost of each operation, then define limits that protect the weakest important dependency. One request count may be unfair when one endpoint performs a cheap lookup and another triggers a costly export or external call.
- Choose the identity: decide whether limits apply per API key, user, tenant, IP address or service account.
- Separate normal rate and burst: a short burst allowance can improve user experience without permitting sustained overload.
- Account for operation cost: expensive endpoints may need stricter limits or weighted request units.
- Define sharing: decide whether limits are global, per region, per endpoint or per customer plan.
- Document exceptions: internal jobs and trusted partners should have explicit ownership rather than hidden bypasses.
- Measure impact: track 429 rates, latency, queue depth, rejected requests and affected customer groups.
A reporting API might allow a small burst for interactive dashboards but use a lower sustained rate for large exports. Exact numbers should come from load tests and service objectives, not from copying another provider's published limits.
What does HTTP 429 Too Many Requests mean?
HTTP 429 means the client has sent too many requests in a given amount of time. RFC 6585 defines the status code and says a response may include a Retry-After header to indicate how long the client should wait before making another request.
Do not assume every API returns the same headers or uses the same counting rule. Read that provider's documentation. A 429 may apply to one endpoint, an account-wide bucket, a secondary protection limit or a longer usage quota.
How should an API client retry after a 429 response?
A well-behaved client respects Retry-After when supplied, otherwise waits using capped exponential backoff with jitter. It should limit retry attempts, avoid synchronized retry storms and protect operations with side effects from accidental duplicate execution. Retry only documented transient responses, not validation or authentication errors.
- Read the response status and documented rate-limit headers.
- If Retry-After is present, wait for the stated interval rather than retrying immediately.
- If no delay is supplied, use exponential backoff and random jitter.
- Set a maximum wait and retry count, then return a clear error or queue the task.
- For payments, orders or other side effects, use the API's documented idempotency mechanism before retrying.
Never treat every 4xx response as retryable. Authentication failures, invalid input and permission errors need correction, not repeated requests. Follow provider-specific guidance for 403 and 429 responses because some services use both codes for rate-limit conditions.
How can you test a rate-limit policy before release?
Test ordinary traffic, short bursts, sustained overuse, multiple app instances and recovery after the window resets. Confirm that legitimate users receive predictable errors, counters remain consistent where required and client retries do not multiply load during recovery. Record the observed result and compare it with service objectives.
| Test case | Expected result |
|---|---|
| Normal request volume | Requests complete within the service objective. |
| Short burst | The configured burst allowance behaves as documented. |
| Limit exceeded | The API returns the documented 429 response and retry information. |
| Several app instances | Shared limits are enforced consistently where the policy requires a global counter. |
| Recovery | Clients resume gradually rather than sending queued work all at once. |
Common API rate-limiting mistakes
- Publishing a limit without saying whether it is per user, key, endpoint or account.
- Using only an IP address when customers share networks or use changing addresses.
- Applying one request cost to every endpoint when workloads differ.
- Returning 429 without a clear message or documented recovery behaviour.
- Allowing every client to retry immediately, creating a thundering herd.
- Assuming a gateway's best-effort throttle is a hard capacity boundary.
Frequently asked questions
What is a common API rate limit?
There is no universal safe number. A public API may set different rates for each plan, endpoint, identity and operation cost. Choose a limit from measured capacity, latency objectives and abuse risk, then publish the scope and burst behaviour clearly.
Does HTTP 429 always include Retry-After?
No. RFC 6585 says a 429 response may include Retry-After, so clients must not assume it is always present. Follow the provider's documented headers and use a conservative backoff strategy when no explicit retry delay is returned. The response may omit the header entirely.
What is the difference between a rate limit and a quota?
A rate limit controls request frequency over a short interval, such as requests per second or minute. A quota usually limits total usage over a longer period, such as a day or billing cycle. Some APIs enforce both controls. Their time horizons and measurement rules differ.
Which rate-limiting algorithm allows bursts?
A token bucket can allow controlled bursts because unused tokens accumulate up to a configured capacity. The refill rate controls the longer-term average. This is useful when brief spikes are acceptable but sustained request volume still needs a limit. Its capacity determines the maximum stored burst.
Should an API client automatically retry every 429 response?
It may retry when the provider documents that behaviour, but it should respect Retry-After, use capped backoff with jitter and stop after a defined number of attempts. For operations with side effects, use an idempotency mechanism to avoid duplicates. It should stop when the documented limit persists.
Key takeaway
Good API rate limiting is a contract between the service and its clients. Define who is limited, select an algorithm that fits the workload, make 429 responses understandable and teach clients to retry safely. Then load-test the policy and monitor its effect on real users.