Search

Search questions, topics, and tracks

0

Rate-limit an API to 100 requests per minute

  • Backend
  • 45 min
  • medium
  • Node.js · TypeScript
The brief — 45 minutes

Our public API is being hammered by a handful of clients. Add a per-key limit of 100 requests per minute in front of it — correct under concurrency, correct across several app instances, and honest with the caller about what it did. Start from an empty middleware file and say what you are trading away as you go.

Requirements

  • Limit by API key: 100 requests per rolling minute, not per calendar minute.
  • Reject over-limit requests with 429 and a Retry-After header.
  • Every response carries the RateLimit-* headers so a client can back off before it is cut off.
  • Correct with several app instances behind a load balancer — the counter cannot live in process memory.
  • Two simultaneous requests on the 100th slot must not both succeed.
  • If the store is unreachable, the API stays up — say which way you fail and why.

Stage 1 of 5 · ~5 min

Pin down what "100 per minute" means

Rolling or fixed, per key or per IP, and what happens on failure

"100 requests per minute" is three unanswered questions, and the interviewer is waiting to see whether you notice.

  • Rolling or fixed window? A fixed calendar minute lets a client send 200 requests across the boundary — 100 at 11:59:59 and 100 at 12:00:00. The requirement says rolling, so the naive counter is already ruled out.
  • Keyed by what? An API key is stated. Ask what happens to unauthenticated traffic — usually a second, tighter limit by IP, which is a different bucket, not the same one.
  • Fail open or fail closed? If the store is unreachable, do you let everything through or reject everything? For a public read API, fail open — an outage in the limiter should not become an outage in the product. For a payments endpoint the answer flips.
  • Is the limit per instance or global? Stated as global, which is what forces a shared store; say it anyway, because it is the constraint that decides the design.
5 of 45 min

Once you finish

The follow-on asks that arrive when you are done early.

  • Different limits per plan, resolved from the key.
  • A burst allowance on top of the sustained rate.
  • Exempt health checks and internal callers without a second code path.
  • Emit a metric per rejection so the limit can be tuned rather than guessed.

What this tests

  • api-design
  • concurrency
  • caching
  • failure-modes
  • observability

Brush up first

Reviewed 24 August 2026