By SecureMigrate12 min read
Rate limiting caps how often a single source can hit a sensitive path, which makes credential stuffing, brute force and API scraping slow and costly rather than cheap and fast. It is one of the lowest-friction defences you can deploy at the edge — but only when the thresholds match how real users and integrations actually behave. This guide walks through which endpoints to protect, how to pick thresholds you can defend, how counting and characteristics work, and how to combine rate limits with challenges and bot signals so legitimate traffic keeps flowing.
What does rate limiting actually do, and where does it sit?
Cloudflare rate limiting runs at the edge, before traffic reaches your origin. A rule counts requests that match an expression — a path, a method, a header pattern — over a rolling time window, grouped by a characteristic such as client IP. When a source crosses the configured count within the period, Cloudflare applies a mitigation action (block, managed challenge, JS challenge, or log) for a defined duration. Because this happens on Cloudflare's network, the abusive traffic never consumes your server's CPU, database connections or licence-limited resources.
It helps to be clear about what rate limiting is and is not. It is excellent at making brute force and scraping uneconomical, because each blocked or challenged request raises the attacker's cost. It is not a complete defence on its own: a distributed botnet spreading requests thinly across thousands of IPs can stay under a per-IP limit, and large volumetric floods belong to Cloudflare's DDoS protection layer rather than to a rate-limiting rule. Treat rate limiting as one layer that pairs with the WAF, bot management and good origin hygiene — not as a single switch that solves abuse.
Rate limiting also complements, rather than replaces, secure development. Account lockout policies, strong password hashing, multi-factor authentication and anti-fraud checks on your application still matter. The edge reduces the volume and pace of attacks reaching your code; your code still has to handle the requests that get through correctly.
Which paths should you prioritise?
Start with the endpoints where automation does the most damage per request. Authentication and account-lifecycle paths are almost always first: login, password reset, magic-link or OTP request, account creation and email verification. These are the targets for credential stuffing and account-takeover attempts, and they are also where abusive traffic can trigger costly downstream effects like outbound emails and SMS charges.
Next, look at expensive or write-heavy API endpoints and anything that can be scraped at scale. Search, autocomplete, product and pricing catalogues, coupon or voucher validation, checkout and payment initiation, file upload, and any endpoint that fans out into third-party API calls all deserve attention. A single unprotected search endpoint can become a free data-export tool for a competitor or a way to exhaust a paid downstream quota.
Map your sensitive surface before you write rules. Inventory the routes, note the HTTP method (you often want to limit POST to /login but leave GET on a public page alone), and record what a normal user's pace looks like on each. This inventory is exactly the kind of groundwork covered in a Cloudflare WAF Setup engagement, where rate-limiting rules are layered alongside managed rulesets and custom firewall logic rather than bolted on in isolation.
- Authentication: login, password reset, OTP/magic-link request, registration, email verification.
- Costly actions: checkout, payment initiation, coupon/voucher validation, outbound email or SMS triggers.
- Scrapeable data: search, autocomplete, pricing and product catalogues, public profile lookups.
- Resource-heavy: file uploads, report generation, and endpoints that call paid third-party APIs.
How do you set thresholds without blocking real users?
Base thresholds on observed legitimate usage, not on a round number that feels safe. Before you enforce anything, deploy the rule in log-only mode for a few days and watch the distribution of request rates per IP on the target path. You are looking for the natural ceiling of genuine behaviour: how many login attempts a real person makes in a minute, how often a mobile app polls an endpoint, how a shared office or carrier-grade NAT IP behaves. Set the threshold comfortably above that ceiling so normal users never reach it, then tighten gradually if abuse continues.
For login specifically, a common starting point is a handful of POST attempts per IP per minute, escalating the mitigation if the source keeps trying. Choose a period that reflects the attack you are countering — short windows (10–60 seconds) catch fast brute force, while longer windows (an hour or a day) catch slow, patient credential stuffing that paces itself to stay under tight per-minute limits. You can run more than one rule on the same path: a short-window rule for bursts and a long-window rule for low-and-slow campaigns.
Prefer graduated responses over an immediate hard block. A managed challenge slows borderline traffic and lets a genuine user through after passing, whereas a block returns a 429 and risks frustrating a legitimate person who simply mistyped their password a few times. Reserve outright blocks for clearly abusive thresholds, and keep the mitigation timeout proportionate — a short cool-off for first offences, longer durations for repeat sources.
How should you count requests — IP, header or JA4?
The characteristic you group by determines how precisely you isolate an attacker. Counting by client IP is the default and works well for many cases, but it has a known weakness: large numbers of legitimate users can share a single IP behind corporate proxies, mobile carrier NAT or VPNs, so an IP-based limit can sweep up innocent traffic. Where that risk is high, group by a more specific signal instead of, or in addition to, IP.
On Cloudflare's advanced rate limiting you can count by a combination of characteristics — for example an authenticated user identifier from a header or cookie, an API key, a JA4 fingerprint, or the value of a specific query parameter. Counting by API key or session token is ideal for API abuse, because it ties the limit to the actual integration or account rather than to the network path it happens to use. For unauthenticated abuse, fingerprinting characteristics help distinguish many bots sharing one IP from many real users sharing one IP.
You can also count only requests that meet a response condition, such as those returning a 401 or 403. This is powerful for login protection: instead of limiting all attempts, you limit only failed ones, so a user who logs in successfully on the first try is never affected while a script grinding through credentials is throttled quickly. Pairing the right characteristic with a response-based counter usually gives you a far cleaner separation between good and bad traffic than a blunt per-IP rule.
How do rate limiting, the WAF and bot management work together?
Rate limiting is most effective as one instrument in an ensemble. The WAF inspects request content and blocks known-malicious patterns; bot management scores how likely each request is to be automated; Turnstile can verify humanity on a form without a clunky puzzle; and rate limiting caps pace. Used together, you can build layered logic that is far harder to evade than any single control. For instance, you might challenge any login request with a high bot score, and separately rate-limit failed logins per IP — so an attacker has to defeat both the behavioural signal and the volume cap.
A practical pattern is to let cheaper signals filter first and reserve rate limiting for what gets through. Bot management and the WAF remove obvious automation up front; rate limiting then handles the subtler abuse that mimics human pacing or rotates just enough to look plausible. This sequencing reduces the load on any one rule and lowers the chance of false positives, because each layer only has to make a decision about traffic the previous layers did not already resolve. Designing this interplay is central to Cloudflare Bot Protection work, where bot scores, challenges and rate limits are tuned as a single system.
Remember that no single tool, and no combination of tools, stops abuse completely — a determined, well-resourced attacker can still probe for gaps. The goal is to make attacks slow, expensive and noisy enough that they are not worth running against you, and to give yourself clear telemetry when someone tries anyway.
How do you protect legitimate API integrations and partners?
The most common cause of a rate-limiting incident is a genuine partner integration tripping a limit, often because all their traffic arrives from one IP or shares an API gateway. Before tightening API limits, identify your known integrations and decide how to treat them. The cleanest approach is to count by API key or partner identifier rather than by IP, and to set per-key thresholds that reflect each integration's contracted volume. A high-throughput partner then gets headroom without you loosening the limit for everyone.
Where you cannot count by a key, maintain an allowlist of trusted sources using IP lists or a skip rule that exempts authenticated, known integrations from the rate-limiting expression. Keep this list documented and reviewed, because stale allowlist entries are a quiet way for protections to erode over time. Communicate published limits to your API consumers and return a clear 429 with a Retry-After header so well-behaved clients back off gracefully rather than hammering harder.
Finally, treat the first weeks after launch as a tuning period. Watch your rate-limiting events, look for legitimate sources clustering near the threshold, and adjust before complaints arrive rather than after. If you would value a second pair of eyes on threshold design, allowlisting strategy and the interplay with the WAF and bot rules, that review is the kind of focused work a Cloudflare Consultant engagement is built around.
How do you monitor, test and tune rate-limiting rules?
Deploy in log-only mode first, then promote to enforcement once the data confirms your threshold is sensible. Cloudflare's Security Events and analytics show which rules are firing, on which paths, and against which sources, so you can distinguish a real attack from a misconfigured limit. Watch the ratio of challenged-and-passed to blocked outcomes: a healthy login rule should be quietly absorbing automated failures while real users sail through.
Test your rules deliberately rather than waiting for an incident. Script a controlled burst of requests against a staging or low-risk endpoint to confirm the threshold, period and action behave as expected, and verify that a normal user journey does not approach the limit. Re-test after any change to your application's traffic patterns — a new mobile app release, a marketing campaign or a partner onboarding can all shift what normal looks like.
Make tuning a recurring habit, not a one-off. Attack patterns evolve, traffic grows and integrations change, so a threshold that was right at launch can become too loose or too tight within months. Schedule a periodic review of your rules, your allowlists and your event logs, and keep notes on why each threshold is set where it is — that record is what lets you adjust confidently instead of guessing.
Want this handled for you?
We configure and manage all of the above as a service, tuned to your platform and traffic.
Request a Cloudflare Audit