Rate limiting caps how many requests a client, user or IP address can make to a system in a given time period, such as 100 requests per minute. When the limit is exceeded, the server delays or rejects extra requests, usually with HTTP 429 Too Many Requests. Common algorithms are fixed window, sliding window, token bucket and leaky bucket, each with different trade-offs for bursts and fairness.
Key takeaways
- Rate limiting caps requests per caller per time window, protecting availability, fairness and cost.
- Token bucket allows bursts, leaky bucket smooths traffic, and sliding window is the most accurate counter.
- Exceeding a limit usually returns HTTP 429 with a Retry-After header; good clients back off and retry.
You have seen it as a user: a login form that locks you out after five tries, or an app that suddenly says "too many requests, try again later." That is rate limiting. It is one of the simplest and most effective defenses in web security — and one of the most misunderstood.
What is rate limiting?
Rate limiting is a mechanism that controls how many requests a client can make to a system within a defined time period. When the number of requests exceeds the allowed limit, the system delays, rejects or throttles the extra requests.
The "client" can be a user, an API key, an IP address or a whole customer account. A typical rule looks like "100 requests per minute per API key" or "5 login attempts per 15 minutes per account."
Rate limiting is enforced at the application, API gateway or network level, where incoming requests are measured against predefined thresholds. Without it, one buggy script, one aggressive scraper or one attacker could consume the capacity everyone else depends on.
Think of it as a bouncer at a busy club. The bouncer does not need to know who you are, only how many people came in recently. When the room is full, the next person waits outside for a bit, which keeps the place usable for everyone already inside.
Why is rate limiting important?
Rate limiting protects availability first. A server has finite CPU, memory and database connections, and every request costs resources. Capping requests per caller keeps one caller from exhausting those resources for everyone.
It also protects fairness. Without limits, one power-hungry user or a broken script sending 50,000 requests a minute slows the service down for every other user. Limits make sure heavy users cannot crowd out normal ones.
Security is the third reason. Rate limiting slows credential stuffing, where attackers try stolen passwords at scale, and it blunts scraping, spam and denial-of-service attacks. A login endpoint that allows unlimited guesses is an open invitation to brute force.
Finally, rate limiting controls cost. Every API response costs the provider money in compute and bandwidth, so public APIs almost always limit free usage and charge for more. That is why your integration needs to respect limits instead of fighting them.
How does rate limiting work?
Rate limiting follows the same sequence for almost every request, whatever the algorithm underneath. First, the client sends a request. Then the system identifies the client, usually by IP address, API key, user account or session.
Next, the system matches the request to a rate limit rule. One endpoint may allow 100 requests per minute while a login endpoint allows only 5, because the risk and cost are different. Then it checks how many requests that client has already made in the current window.
If the count is under the limit, the request is allowed and the counter increases. If the count is over the limit, the request is rejected or delayed. The standard rejection is HTTP 429 Too Many Requests, defined in RFC 6585, often with a Retry-After header saying how long to wait.
Many APIs also tell you your remaining quota before you hit the wall. GitHub's REST API, for example, gives an authenticated user 5,000 requests per hour and reports what is left in the x-ratelimit-remaining header, according to GitHub's rate limit documentation.
What are the main rate limiting algorithms?
Four algorithms cover almost every implementation. They differ in how they count, how they handle bursts, and how much memory they need.
| Algorithm | How it counts | Bursts | Accuracy | Used by |
|---|---|---|---|---|
| Fixed window | One counter per window, reset at the boundary | Allows double burst at edges | Rough | Simple APIs |
| Sliding window log | Timestamp of every request | No edge burst | Exact | Small, precise systems |
| Sliding window counter | Two counters, weighted by overlap | Small edge burst | Very good | Cloudflare |
| Token bucket | Tokens refill at a fixed rate | Allows bursts up to capacity | Good | AWS API Gateway, Stripe |
| Leaky bucket | Requests queue and leak out steadily | Smooths bursts | Good | NGINX limit_req |
Fixed window counter
A fixed window keeps one counter per caller per minute. Every request adds one, and once the count passes the limit the rest are rejected until the next minute starts and the counter resets to zero.
It is simple and cheap, but it has a flaw: a caller can send the full limit at the end of one minute and the full limit again at the start of the next, doubling the burst across the boundary.
Sliding window log and counter
A sliding window log stores the timestamp of every request and counts how many fall inside the last 60 seconds. It is exact, with no boundary to exploit, but it is costly: Cloudflare rejected it because of its "huge processing and memory requirements" at scale.
Cloudflare's sliding window counter keeps just two numbers per caller: this minute and the previous one. It estimates the rate by weighting the previous minute by how much of it still overlaps the window. In Cloudflare's analysis of 400 million requests from 270,000 sources, only 0.003% were wrongly allowed or rate limited.
Token bucket
A token bucket gives each caller a bucket holding up to a set number of tokens, refilled at a fixed rate. Every request takes one token, and when the bucket is empty the request is rejected.
The bucket has two knobs: the refill rate sets the long-run average, and the capacity sets how big a burst a quiet caller can send. This is the algorithm behind AWS API Gateway throttling, where the throttling rate is how fast tokens are added and the burst is the bucket's capacity.
Leaky bucket
A leaky bucket flips the idea around: requests pour into a queue and leak out of the bottom at a steady rate. When the queue is full, new requests overflow and are rejected. NGINX's limit_req module works this way.
The difference from a token bucket is what comes out. A token bucket lets a burst through right away. A leaky bucket smooths traffic into a steady flow, and queued requests pay for that in latency.
What does HTTP 429 Too Many Requests mean?
HTTP 429 means the server counted your requests and refused the next one. RFC 6585, published in April 2012, defines it: "The 429 status code indicates that the user has sent too many requests in a given amount of time."
The response should explain the condition and may include a Retry-After header saying how long to wait, either as seconds or as a date. The RFC deliberately does not define how the server identifies the user or counts requests, so every site decides that for itself.
Not every limit answers 429. GitHub can answer a spent limit with 403 as well as 429, and NGINX's rate limiter answers 503 unless configured otherwise. Cloudflare-protected sites may show "Error 1015: You are being rate limited" when a site owner's rule triggers. Check the response headers, not only the status code.
As a visitor, the fix is simple: stop sending requests, wait as long as the Retry-After header asks, and try again. Repeatedly refreshing usually extends the block. As a developer, the fix is to read the limit headers, back off exponentially with jitter, and never retry before the reset time.
What types of rate limits are there?
Rate limits differ by what they count. Per-user limits cap one account, per-key limits cap one API key, and per-IP limits cap one address. Each choice has a trade-off.
Per-IP limits are easy to apply to anonymous traffic, but they punish everyone behind a shared address, such as an office or school behind one NAT gateway. Per-user and per-key limits are fairer, because they follow the account, not the address — but they only work once the caller is authenticated.
Limits also differ by scope. A global limit caps all traffic to an API, an endpoint limit caps one route, and a tier limit varies by plan: free users get fewer requests than paying customers. Login endpoints usually get the strictest limits of all, because they are the target of credential stuffing.
Client-side limiting is the other half of the picture: a well-behaved client paces its own requests, caches responses and queues retries, so it rarely hits the server's limits at all. Server-side limiting is the enforcement; client-side limiting is the courtesy that makes it unnecessary.
Rate limiting best practices
Set limits from real usage, not from a guess. Measure normal traffic first, then set the limit generously above it — typically two to three times the peak of a normal user — so legitimate users never notice the limit exists.
Return clear, useful responses. A 429 should say what the limit is, when it resets, and how long to wait. Publish your limits in your API documentation, and send the remaining quota in response headers so clients can pace themselves.
Use exponential backoff with jitter for retries: wait 1 second, then 2, then 4, then 8, with a small random delay so thousands of clients do not all retry at the same instant. Cap the number of retries and give up cleanly.
Apply stricter limits to expensive or sensitive endpoints, such as login, password reset and search, and looser limits to cheap reads. And log every limit event: a sudden spike in 429s is often the first sign of an attack, a broken client, or a limit set too low.
Common rate limiting mistakes
The most common mistake is counting by IP address alone. One shared office IP, one VPN exit node or one mobile carrier gateway can represent thousands of people, and a single limit on that address blocks them all at once.
Another mistake is returning a generic 500 or 403 instead of a 429. Clients cannot tell a limit from a bug, so they retry immediately and make the overload worse. A clear 429 with a Retry-After header is a kindness to every client that talks to you.
A third mistake is setting the same limit on every endpoint. A cheap read and an expensive search do not cost the same, and a login attempt is not the same risk as a profile view. Limits should follow cost and risk, not convenience.
Finally, do not forget distributed systems. If you run several servers behind a load balancer, each one counting on its own lets a caller multiply the limit by the number of servers. Shared counters, usually in Redis, are how production systems keep one count across many servers.
The bottom line
Rate limiting is simple in concept and subtle in practice: cap requests per caller per window, return a clear 429 when the cap is hit, and let good clients back off and retry. Token bucket is the best default for most APIs, sliding window is the most accurate, and leaky bucket is the best smoother.
Start by measuring your real traffic, set generous limits, and publish them. A limit nobody hits is a safety net; a limit everyone hits is a bug. You can check your site's public-facing headers right now with our free security headers checker.
Rate limiting is one control among many. Our small business cybersecurity checklist covers the other basics — patching, backups, MFA and email authentication — that belong alongside it.
For the TLS side of the same setup, our free SSL checker confirms your certificate is valid and your site serves over HTTPS.
Frequently asked questions
What is rate limiting in simple terms?
Rate limiting is a rule that says how many requests one user, app or IP address can make in a set time, for example 100 requests per minute. Once the limit is reached, extra requests are delayed or refused until the window resets.
What is HTTP 429 Too Many Requests?
HTTP 429 is the status code a server returns when you have sent too many requests in a given amount of time, as defined in RFC 6585. The response may include a Retry-After header telling you how long to wait before trying again.
What is the difference between rate limiting and throttling?
Rate limiting sets a hard cap on requests in a time window and rejects anything over it, usually with a 429. Throttling slows requests down instead of rejecting them, for example by queueing them. In practice the terms are often used interchangeably.
What is a token bucket algorithm?
A token bucket gives each caller a bucket holding up to a set number of tokens, refilled at a fixed rate. Each request takes one token, and when the bucket is empty the request is rejected. It allows short bursts, because a quiet caller can save up tokens.
How many requests does GitHub allow per hour?
GitHub's REST API allows 60 requests per hour for unauthenticated requests and 5,000 per hour for authenticated requests. GitHub reports the remaining quota in x-ratelimit-remaining and x-ratelimit-reset headers.
Does rate limiting stop DDoS attacks?
Rate limiting helps against DDoS attacks by capping how much traffic any one source can send, but it is not a complete defense on its own. Large distributed attacks need additional layers, such as a CDN, a web application firewall and upstream filtering.
Can rate limiting block legitimate users?
Yes, if limits are set too low or counted by shared IP address, for example an office or school behind one NAT address. That is why good rate limiting uses per-user or per-key limits where possible, returns clear 429 responses, and sets limits generously for normal use.
Sources
- Zapier — What is API rate limiting? The complete guide
- Cloudflare — How we built rate limiting capable of scaling to millions of domains
- IETF — RFC 6585, Additional HTTP Status Codes (429)
- GitHub Docs — Rate limits for the REST API
- PhoenixNAP — Rate Limiting Explained: Algorithms, Use Cases, Best Practices
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against RFC 6585 on HTTP 429, GitHub's REST API rate limit documentation, Cloudflare's rate limiting engineering blog and Zapier's API rate limiting guide.
How we write and fact-check →