"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 

Where it runs

As middleware inside the gateway, not as a separate service you call over the network on every request. For each request the gateway identifies the client, looks up the matching rules in a local cache, runs one atomic Redis operation per rule, then forwards the request or rejects it:

HTTP/1.1 429 Too Many Requests Retry-After: 12 X-RateLimit-Limit: 100 X-RateLimit-Remaining: 0 

Rules live in a config store and are cached in each gateway, refreshed every few seconds, so they change without a redeploy.

Choosing the algorithm

  • Token bucket: two numbers per key, allows short bursts, enforces the average. A good default for APIs.
  • Sliding-window counter: smooth and close to exact "N per minute".
  • Fixed window: simplest, but allows double bursts at the window edges.
  • Sliding log: exact, but stores every timestamp; too much memory at this scale.

The part people miss: atomic updates

Fifty gateways can update the same key at the same moment. If each one reads the counter, decides, then writes it back, two requests can both take the last token. Do the whole check-and-update in one step on the server, with a Redis Lua script (or INCR plus EXPIRE for fixed windows), and let idle keys expire.

When Redis is down

Decide up front. Most APIs fail open with a conservative per-gateway local limit and an alert, so the limiter never takes the API down. Sensitive endpoints such as login can fail closed instead. Across regions, accept a small overshoot rather than paying cross-region latency on every request.

Practise it

Set a 45-minute timer and design it yourself before reading a model answer. The full lesson has the architecture diagram, the data model and a model answer to compare against:
https://looplooplearn.com/courses/system-design/rate-limiter-design/?utm_source=devto

From LoopLoopLearn's free System Design course (no sign-up).