Rate limiting explained: what it protects and what it breaks
A rate limit refuses traffic deliberately, which means the only question that matters is whether it refuses the right traffic. Everything difficult about the subject follows from that: the mechanism is simple, and every hard decision is about who gets counted, over what period, and what happens to somebody the count was wrong about.
What a rate limit actually does
It counts requests against something and refuses them past a threshold. That is the whole mechanism, and its simplicity is misleading, because a limit does not distinguish between traffic you wanted to stop and traffic that merely resembles it.
This makes rate limiting different from every other filtering decision on this site. A rule that matches malformed input refuses something that was already wrong. A rate limit refuses requests that are individually perfectly valid, on the grounds that there have been too many of them, and «too many» is a judgement you made in advance about circumstances you had not seen yet.
The four decisions behind any limit
Every limit answers these, whether deliberately or by accident.
What is counted. Requests are the obvious unit and often the wrong one, because they differ enormously in what they cost you to answer. A hundred cached pages and a hundred searches are the same number and not remotely the same load.
Against what subject. An address, an account, a credential, or the domain as a whole. This choice decides who suffers when the limit is wrong, and it is the decision people give least thought to.
Over what window. A minute, an hour, a day, and whether the count resets abruptly or slides. The window shapes what ordinary use looks like to the counter.
What happens at the threshold. Refusal, delay, or a reduced response. These are not interchangeable, and the difference decides whether a misjudged limit costs you a complaint or a customer.
Why counting by address misleads
The most common subject is the least reliable one, and the reason is structural rather than technical.
A single address routinely carries an entire office, a mobile network's users, a school, or a university. Limiting by address means those people share a budget none of them knows about, and the busiest of them exhausts it for everybody else. Meanwhile anything with a reason to avoid the limit moves between addresses freely, because addresses are cheap and plentiful to whoever is deliberately spreading traffic.
The result is a control that constrains your customers reliably and its intended target barely. Where identity is available, counting against a credential or an account is both fairer and harder to evade, and where it is not, the limit should be set expecting the sharing.
Why a flat limit breaks ordinary clients
Real traffic is not evenly spaced, and a limit that assumes it is refuses people behaving normally.
A page load fetches many things at once. A person returning after lunch opens six tabs. An integration wakes on a schedule and does its work in a burst, then sleeps. Each is ordinary, and each looks identical to a counter watching a narrow window. A limit tight enough to catch abuse in that window is tight enough to catch all three.
The usual answer is to allow a short burst above the sustained rate, which matches how genuine clients behave without raising the long-run ceiling.
Telling the client what happened
A refusal that explains itself is answered correctly; a refusal that does not is retried immediately.
The status code exists to say that the limit, rather than the request, is the problem, and a well-behaved client treats it differently from an error. Alongside it, telling the client when to come back is what turns a retry storm into a pause. Without that, a client with nothing to go on assumes the fastest reasonable thing, which is to try again at once, and the refusals you are issuing become load of their own.
Before you turn one on
Three steps, in order, and the first is the one that gets skipped.
- Watch before enforcing. Record what the limit would have refused against real traffic for long enough to include a quiet day and a busy one. This is the same argument the whole filtering layer rests on, and it applies more sharply here because the traffic being refused is valid.
- List your own automation first. Monitoring, deployment tooling, partner integrations, and scheduled jobs all look like abuse to a counter. Exempting them by credential rather than by address is what keeps the exemption working after infrastructure changes.
- Decide what a wrong decision costs. If refusing a genuine customer is expensive and missing some abuse is not, the limit belongs looser than instinct suggests, and the response belongs gentler than refusal.
What this section covers
The pages below take each decision apart: the counting algorithms and how they differ in behaviour rather than in name, the status codes a blocked client actually sees, limits set per endpoint according to what each costs, the choice between address, account and credential, bursts and smoothing, telling a client when to return, which state to expose in headers and which to withhold, exempting your own automation safely, testing a limit without taking down your own service, what to watch after enforcing, and why counters on separate nodes disagree.
Rate limiting with Bridge WAF
Bridge WAF applies rate limiting per domain, which is the unit limits are defined and counted against. That granularity is worth checking against your expectations before planning around it, since the subject of the count decides what a limit can and cannot express. Requests are inspected at the edge, so traffic that exceeds a limit is refused before reaching your origin rather than after. See what the platform offers at Bridge CDN.
Questions
What is rate limiting?
Counting requests against something and refusing them past a threshold. The mechanism is simple; the difficulty is entirely in choosing what to count, which subject to count it against, over what period, and what to do at the threshold, because those four decide who gets refused wrongly.
Should I limit by IP address?
Only where nothing better is available, and knowing what it costs. One address routinely carries an office, a school, or a mobile network, so those users share a budget they cannot see, while anything deliberately spreading traffic simply moves between addresses.
What should a rate limit return?
The status code meaning the limit rather than the request was the problem, together with an indication of when to come back. Without the second, a client assumes immediately, and the refusals themselves become load, which is the failure mode this is designed to prevent.
How do I stop a limit blocking my own systems?
List your automation before enforcing anything, and exempt each entry by a credential rather than by an address. Credentials survive infrastructure changes and addresses do not, so an exemption written against an address quietly stops matching and nobody notices until something fails at an inconvenient hour.
Do rate limits stop DDoS attacks?
Only the application-layer kind, where requests genuinely arrive and are individually valid. Traffic that saturates a link never becomes a request at all, so nothing counting requests can see it, let alone refuse it. The distinction is set out on attack layers.
The subject of the count is per domain. Watch what a limit would refuse before it refuses anything.
off
No inspection and no counting. Traffic reaches your origin as it otherwise would.
monitor
Requests are inspected and matches recorded. Nothing is refused while you watch.
block
Requests past the limit are refused at the edge rather than after arriving.
The firewall layer is included with Bridge CDN. Start in monitor: nothing is refused until you decide it should be.
Get started