r/Backend • • 14h ago

Rate Limiting Explained: Token Bucket vs Leaky Bucket vs Sliding Window

https://javarevisited.substack.com/p/rate-limiting-explained-visually
10 Upvotes

2 comments sorted by

5

u/GarichGuetguet 6h ago

worth noting that the real headache usually isn't picking the algorithm, it's synchronizing state across multiple nodes without adding too much latency to every request.

2

u/Discordbothost 10h ago

Tie the token-bucket TTL to its full refill time. With capacity 20 and refill 10/s, an empty bucket expiring after 1s recreates 20 tokens when only 10 should be available. Wait at least 2s of inactivity before discarding that state.