Every public API needs a rate limiter, and most teams discover it the same way: one client with a retry loop, or one scraper, takes the service down for everyone else. A limiter caps how much any single key, user or IP can ask for, so one bad actor costs you a 429 instead of an outage.
The design questions are always the same. Which algorithm, where the limiter sits, where the counters live, and what happens when the counter store is down. This post answers each one and ends with an architecture diagram of a distributed limiter in front of an API.
What the limiter must do
Decide in a few milliseconds whether a request is allowed, on every request.
Apply different rules to different callers: per API key, per user, per IP, per route.
Behave the same no matter which server instance handles the request.
Tell clients clearly when they are limited and when to try again.
Keep working, or fail in a predictable way, when its own storage has a problem.
The third point is what makes it a distributed systems…