Rate Limiting: Why its Crucial for API Security and How to Implement It?
Quick answer
Rate limiting caps how many requests a client can make to an API in a set time, which stops attackers from guessing logins and codes, scraping data or overloading your service at machine speed. It works only when it is applied to the right endpoints, keyed to more than an IP address, enforced in more than one layer and tested regularly.
An API that answers every request, however many arrive, can be abused by anyone with a script. Login and password reset flows can be guessed at, lists of accounts can be collected, and expensive actions such as exports or text messages can be triggered over and over. Rate limiting is one of the simplest controls against this, and one of the most often missing or half-built.
This guide explains what rate limiting is, how the main approaches work, how to implement it well, and how to check that it holds up. For testing your APIs against these and other weaknesses, see our API VAPT service.
Key takeaways
- Rate limiting caps requests per client in a time window, so abuse cannot run at machine speed.
- Limit sensitive actions most strictly: login, one-time codes, password resets, payments and anything that triggers a cost.
- Do not rely on IP address alone. Combine limits by account, token and endpoint.
- Enforce limits in layers, return a clear 429 response and log what gets blocked.
- Rate limiting is not a complete defence against large-scale denial of service, so use it alongside other protections.
What rate limiting is and what it stops
Rate limiting is the practice of limiting how many requests a client, such as an IP address, user, API key or token, can make to an API within a time window. Requests over the limit are slowed, rejected or challenged. OWASP lists the underlying risk as API4:2023 Unrestricted Resource Consumption (called lack of resources and rate limiting in its 2019 list), and API6:2023 Unrestricted Access to Sensitive Business Flows covers abuse of business actions such as buying or posting at scale.
| Abuse | What it looks like | Business impact | How limits help |
|---|---|---|---|
| Guessing logins and codes | Many attempts against login, one-time code and password reset endpoints. | Account takeover, and possible exposure of personal information. | Limits slow guessing and can trigger lockouts and alerts. |
| Scraping and enumeration | Automated collection of data, or checking which accounts exist. | Data loss, privacy risk and competitive harm. | Limits cap volume per client and make unusual patterns easy to spot. |
| Resource-heavy actions | Repeated expensive searches, exports or uploads. | Slow service, higher cloud costs. | Tighter limits on costly operations protect capacity. |
| Costly third-party calls | Repeated triggers of text messages, emails or paid checks. | Unexpected bills from providers. | Per-user caps stop one client running up costs. |
| Application-level overload | Volume that degrades or crashes the service. | Downtime and lost revenue. | Fair-use limits keep the service available to everyone, but they are not a full defence against large attacks. |
Why this matters in Australia
If guessing or scraping attacks succeed and personal information is exposed, the Privacy Act expects covered organisations to have taken reasonable steps to protect that information and to notify affected people and the OAIC about eligible data breaches. See the OAIC’s guidance on the Notifiable Data Breaches scheme. APRA-regulated entities must also keep information security controls that match the threats they face under CPS 234. Rate limiting is one practical control that supports these duties.
How rate limiting works
There are a few common ways to count and limit requests. Most real systems combine more than one.
| Approach | How it works | Strength | Watch out for |
|---|---|---|---|
| Fixed window | Counts requests in set blocks of time, for example per minute. | Simple to build and explain. | Bursts at the edge of a window can briefly let through about double the intended rate. |
| Sliding window | Counts requests over a rolling period. | Smoother and fairer than fixed windows. | Needs more memory and processing. |
| Token bucket | A bucket of tokens refills over time and each request spends one. | Allows short bursts while holding a steady average. | Bucket size and refill rate need tuning. |
| Leaky bucket | Requests are processed at a steady rate, and extras wait or are dropped. | Produces smooth, predictable load. | Bursts can be delayed or dropped, which users may notice. |
What to limit by
| Identifier | Good for | Weakness |
|---|---|---|
| IP address | A first, coarse layer of protection. | Many users can share one address, and attackers can spread requests across many. |
| User account | Stopping repeated attempts against one account. | Does not stop one source trying many different accounts. |
| API key or token | Fair use and quotas per customer or app. | Stolen or shared keys carry their limits with them. |
| Endpoint | Applying stricter limits to sensitive or costly actions. | Needs a clear map of your endpoints. |
| Tenant or customer | Protecting shared platforms from one noisy customer. | Needs reliable tenant identification. |
Where limits are enforced: the request path
Enforcing limits in several layers is stronger than relying on one. Each layer catches a different kind of abuse.
Client
Every request starts here. Clients can be users, apps or scripts.
Edge
A CDN or web application firewall applies coarse limits on overall volume.
API gateway
Limits by API key, token, user and endpoint.
Application
Account-level and action-level limits, such as attempts per account.
Backend and suppliers
Quotas on costly resources, such as messages or paid checks.
The edge sees volume, the gateway sees identities, and only the application knows which actions are sensitive. That is why layered limits work better than a single control.
How to implement rate limiting well
These steps take you from no limits to a design that holds up:
1. Map your endpoints
List every endpoint and mark the sensitive ones: login, one-time codes, password reset, account creation, payments, exports and anything that triggers a cost.
2. Set limits by risk
Use stricter limits on higher-risk actions and more generous ones on low-risk, public content. Base the values on your normal traffic.
3. Use more than one identifier
Combine IP address with account, token and endpoint, so a limit cannot be avoided just by changing source address.
4. Return a clear response
Send an HTTP 429 Too Many Requests status with a Retry-After header, and keep error messages from revealing whether an account exists.
5. Respond in stages
Slow clients first, then challenge or temporarily block them, and notify account owners where it makes sense. Be careful that lockouts cannot be used to lock real users out.
6. Cover distributed attempts
Add account-level limits so many sources trying one account are still caught, even if each source stays under its own limit.
7. Log and alert
Record blocked requests and alert on unusual patterns, so limits also give you early warning.
8. Test and tune
Check limits after every release, watch for real users being blocked, and adjust values as traffic changes.
A simple way to set limits by risk
| Risk tier | Examples | Approach |
|---|---|---|
| Higher risk | Login, one-time code checks, password reset, account creation, payments | Strict limits, progressive responses and account-level limits, with alerts. |
| Medium risk | Search, data reads, exports | Moderate per-user limits and quotas, with tighter limits on costly operations. |
| Lower risk | Public, cacheable content | Generous limits that mainly guard against overload. |
Common mistakes to avoid
- Limiting by IP address only
- Trusting forwarding information supplied by the client when working out who is calling
- Using one limit for every endpoint
- Applying limits to the website but not to older or undocumented API versions
- Enforcing limits only in the front end
- Not logging blocked requests
How to check your rate limiting
Rate limiting often looks fine in design and fails in practice. These are the checks to make, whether you do them in-house or ask a tester to confirm them:
| Check | What good looks like | Common gap |
|---|---|---|
| Sensitive endpoints are covered | Login, code checks, reset and payment flows all have limits. | Limits exist on the main login only. |
| Limits do not depend on one identifier | Limits apply by account and token as well as source address. | A single IP-based limit that is easy to sidestep. |
| Correct response | An HTTP 429 with a Retry-After header and a neutral message. | Normal success responses, or error text that reveals account details. |
| Every route and version is covered | Old, beta and undocumented endpoints have the same limits. | Limits applied to the current version only. |
| Slow and spread-out attempts are caught | Account-level limits and alerts catch low-volume patterns. | Only short, fast bursts are blocked. |
| Costly actions are capped | Messages, exports and paid checks have per-user caps. | No cap on actions that cost money. |
| Blocks are logged and alerted | Blocked requests appear in logs and trigger alerts. | Limits work silently with no visibility. |
| Real users are not blocked | Normal use never reaches the limit. | Limits set so tight that customers hit them. |
Test safely
- Agree the scope, timing and rules in writing before any testing starts
- Test on a staging copy first where you can
- Use dedicated test accounts and never real customers
- Avoid triggering real text messages, payments or other charges
- Agree how testing stops if something goes wrong, and tell your operations team
A penetration test of your API includes these checks as part of its scope. See our API VAPT service for how we approach it.
Frequently asked questions
What is API rate limiting?
API rate limiting caps the number of requests a client can make to an API in a set time window. Requests over the limit are slowed, rejected or challenged. It protects against guessing attacks, scraping, overload and runaway costs.
Why is rate limiting important for API security?
Without it, anyone with a script can make thousands of requests, which allows guessing of logins and one-time codes, collection of data, repeated use of costly actions and strain on your service. Rate limiting makes those attacks slower, noisier and easier to detect.
What is the difference between rate limiting and throttling?
Rate limiting sets a maximum and rejects or blocks requests above it. Throttling slows requests down instead of rejecting them. Many systems use both, for example slowing a client first and blocking it if it continues.
What should I limit requests by?
Use more than one identifier. IP address is a useful coarse layer, but also limit by user account, API key or token, and endpoint, and add account-level limits to catch attempts spread across many sources.
Which HTTP status code should I return when a limit is exceeded?
Return HTTP 429 Too Many Requests, ideally with a Retry-After header telling the client when to try again. Keep the message neutral so it does not reveal details such as whether an account exists.
Is rate limiting enough to stop denial-of-service attacks?
No. Rate limiting helps keep your service fair and available under heavy use, but large-scale attacks need additional protections such as capacity planning, network and edge defences and monitoring. Treat rate limiting as one layer.
How do I choose rate limit values?
Start from your normal traffic. Measure how real users behave, set stricter limits on sensitive and costly actions, and loosen or tighten them as you watch for real users being blocked. There is no single correct number, because it depends on your API and users.
How can I tell whether my rate limiting works?
Review your limits against a checklist covering sensitive endpoints, multiple identifiers, correct responses, all API versions, logging and alerts, and test them safely with written authorisation. A penetration test of your API can confirm that the limits hold up in practice.
Find out whether your API limits really hold
Tell us about your APIs. We will explain your options and send a clear scope and quote for an API security test.
CyberSapiens, Level 1, 206 Lorimer St, Port Melbourne VIC 3207
Get a free API security quote