Lesson 7 of 9 · 20m
Rate Limiting and Bot Management at the Edge
Admission control close to the user: counters, dimensions, burst behavior, bot signals, and how not to lock out customers.
Rate limiting is admission control, not revenge. Its job is to protect scarce capacity and raise attacker cost while legitimate users barely notice it exists. Done badly, it becomes a distributed denial-of-service against your own customers — especially mobile networks where thousands of people share one NAT address.
Choose the counter dimension before the number
"100 requests per minute" is meaningless until you say per what. Common dimensions:
per IP: ip.src
per session: http.cookie["session"]
per account/API key: value extracted or matched in a header
per path: http.request.uri.pathPer-IP is cheap but coarse. Per-account is precise but only exists after authentication. Per-path protects expensive endpoints without throttling cheap ones. Mature systems combine them: loose global IP limits, tighter limits on login and password reset, and strict quotas on expensive API operations.
Burst behavior is the user experience
A limit of 60 requests per minute does not mean clients arrive politely once per second. Browsers parallelize, SPAs retry, and users double-click. Use periods and actions that absorb normal bursts:
Expression:
http.request.uri.path eq "/login" and http.request.method eq "POST"
Rate:
10 requests per 1 minute per IP
Action:
Managed Challenge for 10 minutesFor APIs, 429 Too Many Requests with Retry-After is usually better than a challenge because machines can obey it. For human login flows, a challenge is often kinder than a hard block.
Bots are a spectrum, not a binary
Cloudflare bot scores combine signals — TLS fingerprinting, behavior, reputation, automation frameworks. Do not equate "automated" with "malicious." Search engines, status monitors, accessibility tools, partner integrations, and your own CI are all bots.
Separate policy by consequence:
- Verified good bots: allow what the business needs.
- Unknown automation on cheap static paths: often harmless.
- Automation on credential endpoints: challenge or throttle aggressively.
- Clients with valid API credentials: quota them as customers, not as anonymous noise.
Edge enforcement must fail closed on abuse, open on ambiguity
If bot detection infrastructure has a bad day, hard-failing every ambiguous request can take down real users. Bias uncertain traffic toward challenge or monitoring, and reserve deterministic blocks for high-confidence exploit patterns or clearly violated quotas.
Field notes
- Login, signup, password reset, coupon validation, and search endpoints deserve their own limits. One global rule is a blunt instrument.
- Count what costs you money or risk, not what is easiest to count.
- Tell API customers the quota contract and return consistent headers. Surprise throttling creates retry storms.
- Watch NAT-heavy populations separately; a rule tuned on office broadband can be disastrous on carrier-grade NAT.
Was this lesson helpful?