Design a rate limiter
A system design walkthrough of a rate limiter: requirements, where it runs, the fixed window, sliding log, sliding window counter, token bucket and leaky bucket algorithms with code, a distributed limiter on Redis with atomic Lua scripts, response headers, and failure handling.
CodexBash, , 7 min read
Every public API needs limits. Without them, one buggy client in a retry loop, a scraper, or an attacker guessing passwords can consume all your capacity and take the service down for everyone. A rate limiter caps how many requests each client may make in a period, rejecting the excess with HTTP 429 Too Many Requests. "Design a rate limiter" is also a favourite system design interview question, because it combines algorithms, distributed state and careful trade-offs in a compact problem. This article works through it.
Sign in to read the rest
The whole 7 minute article is free with an account, along with every problem, lesson and tutorial. No card.