Dev.to
7/11/2026

Designing a Rate Limiter: Token Bucket vs Sliding Window, and Making It Distributed
Short summary
A detailed comparison of rate limiting algorithms — token bucket, sliding window log, sliding window counter, and fixed window — with practical guidance on making them distributed using Redis. The key insight is that atomic read-modify-write via Redis Lua scripts prevents race conditions across servers. Real-world examples from Stripe and Cloudflare illustrate production patterns.
- •Token bucket is cheap and burst-friendly; sliding window counter offers smoother limits at slightly higher cost
- •Distributed rate limiting requires atomic operations — Redis Lua scripts ensure no race conditions across servers
- •Stripe uses token bucket in Redis; Cloudflare pushes limiting to the edge for early rejection
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



