Free course · 20 lessons · Intermediate
Rate Limiting, Quotas & Abuse Protection
Protect APIs with the right algorithms (windows, token bucket, GCRA), distributed limiters, RateLimit headers, quotas and plans, concurrency and cost-based limits, fairness, and defenses against credential stuffing, bots and abuse.
1. Rate Limiting Fundamentals
Why limit, which algorithm to use, and what to limit by.
- Why Rate Limit? — Protect availability, fairness, cost and security.
- Fixed Window, Sliding Log and Sliding Window Counter — Counting algorithms and their accuracy/cost trade-offs.
- Token Bucket and Leaky Bucket — Allow bursts while enforcing an average rate, or smooth output.
- GCRA: The Generic Cell Rate Algorithm — A memory-efficient, precise limiter used by many modern implementations.
- What to Limit By: Keys and Dimensions — Per IP, user, API key, tenant, endpoint and cost.
2. Distributed Implementation
Redis limiters, local vs global limits, headers, quotas and concurrency limits.
- Distributed Limiters with Redis and Lua — Atomic, shared limits across many app instances.
- Local, Global and Hybrid Limits — Trade accuracy for latency at very high request rates.
- Communicating Limits: Headers and 429 Responses — Tell clients their limits and when to retry.
- Quotas, Plans and Usage Limits — Long-period allowances tied to pricing tiers.
- Concurrency Limits and Adaptive Limiting — Cap in-flight work and adapt limits to observed latency.
3. Where and What to Enforce
Edge vs app limits, cost-based limits and fairness in multi-tenant systems.
- Limits at the Edge and Gateway — CDN/WAF and API gateway rate limiting.
- Application-Level Limits — Business-aware limits implemented in your services.
- Cost-Based Limits: GraphQL, Search and LLM Tokens — Limit by the work a request causes, not the number of requests.
- Fairness and Noisy Neighbors — Keep one tenant from degrading everyone else.
4. Abuse Protection and Operations
Credential stuffing, bots, abuse signals and operating limits safely.
- Defending Login and Account Endpoints — Credential stuffing, brute force, OTP abuse and account enumeration.
- Bots, Scraping and Automated Abuse — Distinguish good bots, bad bots and humans.
- Abuse Signals and Detection — Detect abuse patterns rate limits can't catch.
- Testing and Operating Rate Limits — Roll out limits safely and keep them healthy.
5. Capstone
Design rate limits for a public API and stop a login attack.
- Capstone: Rate Limits for a Public API — Design the complete rate-limiting and quota scheme for a developer API.
- Capstone: Stop a Credential-Stuffing Attack — Respond to an active attack and harden login permanently.