"Design a rate limiter" is one of the most common system design interview questions, because it looks small and isn't. Here's a compact walkthrough of the version most interviewers expect: one limiter shared by many API gateway instances.
The problem
A public API with limits per API key and per endpoint: say 100 requests a minute on the free plan and 5,000 on paid. 50 gateway instances handle 500,000 requests a second between them, and the limiter may add only a few milliseconds.
Quick estimates
checks : 500,000 / s (one per request) active keys : ~10M, ~100 bytes per counter -> ~1 GB in memory Redis : ~100k simple ops/s per node -> 5-10 shards, plus replicas
Enter fullscreen mode
Exit fullscreen mode
Where it runs
As middleware inside the gateway, not as a separate service you call over the network on every request.…