How we built rate limiting capable of scaling to millions of domains
Jun 7, 2017Julien Desgats

Summary
This post details the implementation of Cloudflare's rate limiting system, designed to scale to millions of domains. It describes the challenges of distributed rate limiting across an anycast network, the use of a Twemproxy cluster with memcached for shared counters within each PoP, and the adoption of a sliding window algorithm for accurate rate approximation. The system leverages asynchronous counter increments and in-memory caching of mitigation states to handle high-volume L7 attacks efficiently without impacting legitimate traffic.
More from the Website Security & Threat Management trail
- We tested our own WAF with frontier AI models. Here’s what we found
- When scanners miss the attack: how Cloudflare Client-Side Security protects storefronts
- Introducing automatic remediation policies with Cloudflare CASB
- Introducing context-aware vulnerability discovery and remediation with Cloudflare Managed Defense and OpenAI Daybreak Models
- Introducing Adaptive Intelligence: undermining the economics of every bot attack