What is API Rate Limiting and How to Implement It
Everything in this world is built with finite resources.
Restaurants, for example, contain a maximum number of seats, and when the restaurant is forced to serve significantly more people than this number, the quality of service decreases (i.e. slow delivery) and the guest’s safety can even be put at risk.
The same principle is applied to Application Programming Interfaces (APIs), where a “rate limit” is applied to ensure the API can provide optimal quality of service for its users, while also ensuring the safety of the API’s users.
For example, rate limiting can protect the API from slow performance when too many bots are accessing the API for malicious purposes, or when a DDoS attack is currently affecting the API. Also, when too many legitimate users are accessing the API, a rate limit can be useful.
TL;DR
- API rate limiting controls access to prevent infrastructure overload by limiting the number of requests per time period
- Critical for security and performance: Protects against bot attacks, DDoS, and API abuse that cost businesses up to $186 billion annually
- Implementation methods: Fixed window, leaky bucket, sliding log, and sliding window algorithms
- DataDome blocks bad bots automatically while rate limiting controls good bot and commercial traffic volume
- Real impact: Organizations like OffenderWatch reduced requests from 80 million to 2.5 million per day, saving hours of manual work
Summary:
- What is API rate limiting?
- Why is API rate limiting necessary?
- How does API rate limiting work?
- Different methods for API rate limiting.
- API rate limiting with DataDome.
What is API rate limiting?
The basic principle of API rate limiting is fairly simple: if access to the API is unlimited, anyone (or anything) can use the API as much as they want at any time, potentially preventing other legitimate users from accessing the API.
API rate limiting is, in a nutshell, limiting access for people (and bots) to access the API based on the rules/policies set by the API’s operator or owner.
We can think of rate limiting as a form of both security and quality control. This is why rate limiting is integral for any API product’s growth and scalability. Many API owners would welcome growth, but high spikes in the number of users can cause a massive slowdown in the API’s performance. Rate limiting can ensure the API is properly prepared to handle this sort of spike.
An API’s processing limits are typically measured in a metric called Transactions Per Second (TPS), and API rate limiting is essentially enforcing a limit to the number of TPS or the quantity of data users can consume. The need for effective rate limiting has become critical as API attacks escalate. In 2023, automated threats generated by bots accounted for 30% of all API attacks, with bot-related security incidents rising 28% from the previous year. Organizations with revenues exceeding $1 billion are 2–3× more likely to experience automated API abuse than smaller businesses, making rate limiting essential for enterprise API protection.
That is, we either limit the number of transactions or the amount of data in each transaction.
Why is API rate limiting necessary?
API rate limiting can be used as a defensive security measure for the API, and also a quality control method. As a shared service, the API must protect itself from excessive use to encourage an optimal experience for anyone using the API.
Rate limiting on both server-side and client-side is extremely important for maximizing reliability and minimizing latency, and the larger the systems/APIs, the more crucial rate limiting will be.
Here are some key benefits in implementing API rate limiting:
Protecting resource usage
All APIs operate on finite resources, and rate limiting is essential to improve the availability of API service for as many users as possible by avoiding excessive resource usages. While resource starvation can be caused by attackers via DDoS attacks, there are actually many DoS incidents that are caused by errors in software rather than outside attacks.
This is often called friendly-fire denial of service (DoS), and implementing rate limiting is crucial to avoid this issue.
Controlling data flow
This is especially important in APIs that process and transmit large volumes of data. Rate limiting can be implemented to control data flow, for example by merging many data streams into a single service.
For example, we can distribute data more evenly between two elements of the APIs by limiting the flow into each element. Thus, we can prevent a single API data processor from processing too many items while other processors are currently idle. This function is especially useful in complex APIs that involve different data streams.
Maximizing cost-efficiency
Rate limiting can be implemented to control cost, for example, to prevent using too many resources, which may accumulate large costs. Any resource consumed will always generate a cost, and the more requests an API gets, the more costs it will accumulate. Rate limiting can be extremely important to ensure the profitability of the API.
Organizations that implement effective rate limiting alongside bot protection see dramatic results. Josh Bruner, CEO at OffenderWatch, shared: “We went from 80 million requests a day to 2.5 million. I got back hours of my day, and we turned what was being scraped for free into a paid product.” OffenderWatch customer story
Before implementing protection, OffenderWatch spent 2 to 3 hours daily managing rules manually.
“Just the fact that I personally used to spend a lot of time looking at server logs, searching for patterns, and trying to figure out what was going on obviously had a cost. And the time spent on this issue for the rest of the development team has also been eliminated, which is a massive cost saving.”
Controlling quotas between users
When the capacity of an API’s service is shared among many users, rate limiting can (and should) be applied to individual users’ usage to ensure fair use without disrupting other users’ access. We can do this by applying the rate limit over a certain time period (i.e. per day) or by limiting the resource’s quantity when it’s possible. These allocation limits are often referred to as quotas.
How does API rate limiting work?
An API is a method to request a specific functionality of a program. While APIs are invisible to most users, they are essential for the application to perform optimally.
For example, when we order a ride on a rideshare service, an API is executed so that we, as a user, will get an accurate fare for the trip. We don’t interact directly with this API, but through the rideshare app’s interface we are making a request to the API, probably without our knowledge.
Every time an API responds to a request, the owner of the API has to pay for resources. In the example above, the rideshare app’s API integration will cause the fare calculation service to pay for compute time whenever an app user requests a ride.
Thus, any service that offers API for developers will implement a rate limit on how many API calls can be made. The limiting can be performed in various different ways, like limiting the number of API calls per hour, day, or unique user, or limiting the amount of data generated per call, among others.
API rate limiting can also help protect the API from malicious bot attacks and DDoS attacks. Bots can make repeated requests to an API to block its service from legitimate users, slow down its performance, or completely shut the API down for a time as a form of DDoS attack.
According to the 2024 State of API Security report for Financial Services, 42% of API breaches result from fraud, abuse, and misuse, with malicious bots posing a significant threat1>. However, only 15% of organizations feel confident in detecting and preventing API-based fraud1>, highlighting why rate limiting must be part of a comprehensive security strategy that includes bot detection and behavioral analysis.
Different Methods of Rate Limiting
As discussed above, we can actually use various methods in performing API rate limiting, but there are three most common methods:
1. Throttling
Throttling is performed by setting up a temporary state within the API, so the API can properly assess all requests. Based on certain rules, a specific type of request will be throttled during this temporary state; when throttled, a user may either be slowed considerably (by reducing the bandwidth service) or completely disconnected from the API.
We can implement throttling at the API level, user level, and application level, making it a versatile method for rate limiting.
2. Request queues
Another popular method of rate limiting is “requests queues”, which limits the number of requests in any given period of time. For example, we can set the rate limit at three requests per second.
3. Algorithm-based
In this approach, we are using algorithms to implement the API rate limit, and there are actually various ready-to-use algorithms we can use to implement rate limiting:
- Fixed window
In this method, we use a “fixed” number as a limit, and we use a simple incremental counter to count the number of requests. If this fixed window limit is reached in a set period of time (i.e. 3,000 per hour), then additional requests will be blocked temporarily.
- Leaky bucket
Here the requests are put in a FIFO (first in first out) queue, so the first user that enters the queue will get the first service from the API.
- Sliding log
In this method, a time-stamped log is used to identify different user logs. With each new request, the total number of the logs is calculated, and when logs exceed a certain rate limit, they will be discarded.
- Sliding window
Essentially combining fixed window and sliding log algorithms, with this approach both a counter and a log are used to determine a faster rate limiting process. The small number of data needed to assess each request allows a faster calculation process, making it ideal for processing a large number of requests.
Rate limiting methods comparison
| Method | Best Use Case | Pros | Cons |
|---|---|---|---|
| Throttling | Real-time traffic management | Flexible, granular control | Can slow legitimate users |
| Request queues | Predictable traffic patterns | Fair ordering, simple logic | May create delays during spikes |
| Fixed window | Straightforward volume control | Easy to implement | Burst traffic at window edges |
| Leaky bucket | Smooth traffic flow | Consistent processing rate | Complex implementation |
| Sliding log | Precise rate calculation | Accurate tracking | Higher memory requirements |
| Sliding window | High-volume APIs | Fast calculation, accurate | More complex than fixed window |
Choosing the right method depends on your API’s traffic patterns, infrastructure capacity, and security requirements. For comprehensive protection, combine rate limiting with AI-powered bot detection like DataDome’s API Protection that automatically identifies and blocks malicious traffic before it reaches your rate limiting rules.
API rate limiting with DataDome
DataDome’s bot and agent trust management software combines advanced rate limiting capabilities with AI-powered bot detection, providing a comprehensive approach to API security.
How DataDome enhances rate limiting
With DataDome’s API Protection, you can implement rate limiting to control traffic to your APIs based on the number of requests generated during a specified time period (fixed window method). DataDome blocks bad bots by default, but for good bots or allow-listed traffic, requests are permitted until they reach your defined threshold. Once the threshold is met, DataDome either blocks the request or presents our CAPTCHA alternative: DataDome Slider.
Key capabilities:
- Real-time detection in under 2 milliseconds without compromising performance
- Multi-layered AI engine analyzes 5 trillion signals daily to identify threats before they reach your rate limits
- Less than 0.01% false positive rate ensures legitimate traffic flows smoothly
- 30+ global points of presence (PoPs) for low-latency protection worldwide
Configuration and flexibility
To apply rate limiting with DataDome, simply open the Response menu in the dashboard and select Rate Limiting. You can configure:
- Threshold definition: Set the number of hits that define your volume threshold. All traffic is allow-listed until reaching this limit.
- Time period: Define the duration during which the threshold applies.
- Response action: Choose between our CAPTCHA alternative: DataDome Slider, or hard block once traffic exceeds the threshold.
Rate limiting settings can be applied to any chosen “good” or commercial bot traffic (AI rules) and to all custom rules, giving you precise control over your API traffic.
Proven results
Organizations using DataDome’s API protection see significant impact:
- CAPFM achieved a 30–40% decrease in bot traffic and scraping activity
- D-EDGE saw a 75% reduction in total bot traffic after deploying DataDome
- Ladders reduced infrastructure costs by 15–20% through effective bot blocking and rate limiting
Kilian Chiarelli, IT Manager at CAPFM, explained: “Before DataDome, bots could hit us freely. Once they were blocked, they started changing tactics, but DataDome’s detection models evolve just as fast.”
Conclusion
API rate limiting is no longer optional—it’s essential infrastructure protection. With API-related security incidents growing 9% in 2023 and bot-related incidents jumping 28%, organizations must implement sophisticated rate limiting combined with intelligent threat detection.
Effective rate limiting delivers three critical benefits:
- Security: Protects against DDoS attacks, bot abuse, and API exploitation that cost businesses billions annually
- Performance: Ensures optimal service delivery for legitimate users by preventing resource exhaustion
- Cost control: Reduces infrastructure costs and operational overhead from managing malicious traffic
The evolution toward AI-driven threats means rate limiting must work alongside intelligent bot detection. DataDome’s cyberfraud protection platform blocks over 400 billion attacks annually, stopping sophisticated bots before they reach your rate limiting rules. This layered approach—AI-powered detection combined with flexible rate limiting—ensures your APIs remain secure, performant, and cost-effective.
Ready to protect your APIs? Book a demo to see how DataDome combines rate limiting with real-time bot detection to secure your infrastructure.
Frequently asked questions about API rate limiting
Rate limiting sets hard boundaries on the number of requests allowed within a time period, while throttling slows down request processing when limits are approached. Rate limiting typically results in blocked requests once the threshold is met, whereas throttling gradually reduces bandwidth or introduces delays. Both can be used together as part of a comprehensive API protection strategy.
Choose based on your traffic patterns and security needs:
- Fixed window: Best for simple volume control with predictable traffic
- Sliding window: Ideal for high-volume APIs needing accuracy without high memory costs
- Leaky bucket: Best when you need smooth, consistent traffic flow
- Token bucket: Allows for burst traffic while maintaining overall rate control
For APIs facing sophisticated bot attacks, combine algorithmic rate limiting with AI-powered bot detection like DataDome that adapts to evolving threats in real-time.
No. While rate limiting controls volume, it cannot distinguish between legitimate high-volume users and malicious bots with distributed IP addresses. According to industry research, 42% of API breaches result from fraud and misuse1>, but only 15% of organizations can effectively detect API-based fraud1>. Effective API protection requires rate limiting combined with behavioral analysis, bot detection, and threat intelligence.
When properly configured, rate limiting should not impact legitimate users. Set thresholds above normal usage patterns and monitor for false positives. DataDome’s approach maintains a less than 0.01% false positive rate, ensuring legitimate traffic flows freely while blocking malicious requests. Organizations like Tap Global report zero customer complaints about access issues after implementation.
Savings vary by organization size and threat exposure, but the impact can be substantial. OffenderWatch reduced daily API requests from 80 million to 2.5 million, saving 2–3 hours of manual work daily. Ladders saw infrastructure cost reductions of 15–20%. More broadly, vulnerable APIs cost businesses up to $87 billion annually making effective protection a critical investment.
DataDome provides flexible rate limiting integrated with AI-powered bot protection:
- Customizable thresholds for hits/requests over defined time periods
- Granular control at the endpoint, user, and application level
- Multiple response options: hard block or CAPTCHA alternative challenge: DataDome Slider
- Real-time dashboard with analytics and automated reporting
- Integration with 50+ CDNs, API gateways, and infrastructure platforms
Learn more about DataDome’s API Protection solution.
References
DevOps Digest article citing 2024 State of API Security: Financial Services report: https://www.devopsdigest.com/api-security-in-financial-services-navigating-regulatory-and-operational-challenges