This article first appeared on AlgoSimplified . That URL is canonical. The full lesson has the exercises and a short quiz; this is a shorter cut of the same design.
There is a full system-design lesson for this, rather than an LLD one. The Redis course also has a smaller sliding-window and token-bucket section; the design below is the HLD case study.
The problem
Design a service that limits how many requests a client can make, for example 100 requests per minute per API key. It protects services from abuse and overload, enforces pricing tiers, and keeps one noisy customer from hurting the rest.
A reasonable set of requirements:
Limit by a key (user id, API key, IP) with per-rule limits ( /login : 5/min per IP; API: 1,000/min per key).
Reject excess requests with 429 Too Many Requests and a Retry-After header.
Low added latency (a millisecond or two), and correct behaviour across many API servers.
If the limiter itself fails, fail open (let traffic through) rather than taking the whole API down, for…