Abuse prevention

API Rate Limiting Best Practices

Set fair quotas, give clients clear retry signals, and test whether limits hold under real traffic.

Published: 19 September 2026 · APISAST

Updated: 19 September 2026

Start with a policy for each operation

API rate limiting best practices begin with the cost of an operation and the identity of its caller. A search endpoint, login endpoint, and bulk export should rarely share the same quota. Decide whether the key is a user, client application, tenant, or another verified identity. An IP-only policy can punish users behind a shared gateway and may be easy to evade.

Set a sustained request rate and a small burst allowance. Keep a separate concurrency or work budget for expensive operations. Rate limits reduce abuse and resource exhaustion; they do not replace authentication or authorization.

Choose the enforcement model

A token bucket allows short bursts while controlling the long-term rate. A sliding window can give smoother per-period limits. Whichever model you choose, coordinate state across API instances or enforce at a gateway. Test edge cases such as concurrent requests, retries, clock differences, and tenant isolation.

Make deliberate exceptions for trusted internal jobs, with separate credentials and observable quotas. A blanket bypass for an entire network can hide an abusive client.

Return useful 429 responses

When a caller exceeds a limit, return HTTP 429 and a Retry-After value when the next attempt is predictable. Document the response and any quota headers your implementation actually sends. Keep error bodies consistent with the rest of the API; the API error handling guide explains how to do that without leaking internals.

HTTP/1.1 429 Too Many Requests
Retry-After: 30
Content-Type: application/problem+json

{"type":"about:blank","title":"Too Many Requests","status":429}

Clients should back off, use jitter, and avoid retrying unsafe writes unless they have an idempotency strategy. A response header is useful only when the enforced policy matches what the documentation promises.

Set quotas from measured cost

Begin with the work each request creates. A cached lookup and an export that reads thousands of records should have different budgets. Measure CPU time, downstream calls, database work, and response size before choosing values. Set limits by a stable authenticated identity where possible, then decide whether tenants need a shared budget across all their users. A per-user limit alone may fail to protect a shared backend if one organisation creates many accounts.

Document both the normal rate and the burst policy in developer-facing guidance. Include whether limits are per minute, per day, or concurrent request, and how clients can request a higher quota. If the policy changes, version the documentation and notify affected consumers. The numbers in an OpenAPI example should match the deployed gateway or service policy; a header declaration is not enforcement.

Avoid bypasses across regions and instances

A limit kept only in one application process can be bypassed by sending requests through another instance. Place enforcement at a shared gateway or use coordinated state that matches the availability needs of the API. Decide what happens if the limiter's backing store fails: a login endpoint might need a stricter fallback than a public read endpoint. Record the decision and test it rather than allowing an accidental fail-open policy.

For multi-region services, think about whether a quota is global or regional. A global limit may require coordination that adds latency; a regional limit may let a caller consume the allowance in every region. Test traffic that switches regions, credentials, and IP addresses. Monitor how often legitimate clients receive 429 and how much expensive work is rejected before it reaches the backend.

Help clients back off safely

A 429 response should tell a client when to try again if the server can calculate that interval. Retry-After can contain a delay in seconds or an HTTP date; pick a form and use it consistently. A client library should respect the value, add jitter when many workers retry together, and cap the number of attempts. Retry only requests that are safe to repeat, or use idempotency keys for operations that create resources.

Distinguish rate exhaustion from authentication errors and service failures in dashboards. A sudden increase in 429 from one client can signal abuse, an unintended retry loop, or a quota that is too low. Review request volume and business impact before blocking a legitimate integration. Document a support path so customers know how to diagnose a limit without sharing credentials in tickets.

Test limits as a property of the running API

Write a contract test for the documented 429 response and headers. Then send controlled bursts from one identity and from multiple identities to confirm the actual boundary. Verify that a client cannot escape a tenant quota by rotating application keys, and that one customer's traffic cannot exhaust another customer's allowance. A load test should also confirm that the gateway rejects requests before expensive work begins.

Keep test traffic away from production users unless the environment is designed for it. Record the observed reset behaviour and compare it with the documentation. APISAST can report a missing rate limit header declaration; only these runtime tests can show whether the promised policy is active.

Repeat the test after changing a gateway rule or adding another API instance. Configuration drift can reintroduce an abuse path even when the OpenAPI file remains unchanged.

Check documentation, then verify behaviour

APISAST can flag a specification that does not document rate limit response headers. It cannot measure the live quota or prove that the gateway blocks a burst. Scan the contract with the static API security scanner, then load-test the enforcement path and monitor 429 rates by client and operation.

For collection endpoints, combine quotas with bounded pagination so each permitted request also has predictable cost.

More API security guides