Skip to content
BytePatterns

Design a Rate Limiter

System Design Cases: lesson 2 of 20

The algorithm is easy; where the counter lives is the interview.

Lesson 2 of 20 · 6 min

Design a Rate Limiter

Step 1 of 11

Ten thousand requests a second, three gates, and one budget per API key.

The Idea

Cap what any one caller can spend. Assume 10 000 requests a second across three gateway nodes, 100 000 API keys, and a budget of 100 requests a minute each. Naming the algorithm is the easy half.

Real-World Example

A festival wristband, scanned at every gate. If each gate kept its own clipboard you could walk in three times, so the gates read from one shared list — and the queue now depends on that list being up.

The Tradeoff

Per-node counters need no network hop and let a caller spend N times the limit across N nodes. One shared store is exact and adds a round trip to every request, plus a dependency you must plan for: decide now whether an unreachable limiter fails open and serves everything, or fails closed and rejects everyone.

Your turn

Put the steps in the right order.

  1. If the counter store is unreachable, fail open and serve the request
  2. Resolve the caller's identity key from their API key or token
  3. Reject with 429 and Retry-After once the budget is gone
  4. Atomically increment that key's counter in the shared store

Mini quiz

1 / 3

Three gateway nodes each keeping their own counter means one caller can:

New lessons land every few weeks

Leave an address and we will tell you when the next one is up. That is the only reason we will use it.

One address, stored so we can email you. Nothing else, ever.