A rate limiter for a public API

An API behind several servers needs fair per-customer limits that hold across all of them.

To design a rate limiter, pick an algorithm such as token bucket, keep each customer's counters in a fast shared store so every server agrees, make the check-and-decrement atomic, return a 429 with a retry hint, and decide whether the limiter fails open or closed when its store is down.

The system today: A company sells a public API. Requests reach a load balancer, which spreads them over eight identical API servers, and each server talks to the same database. There is no limit today: one customer's runaway script recently slowed everyone down.

What has to change: Design rate limiting so each customer gets a fair quota (for example 100 requests a minute, with short bursts allowed), the limit holds across all eight servers, and a rejected request tells the caller when to retry. The limiter must not become the new bottleneck or a single point of failure.

Questions to ask first

Where the interviewer digs in

What a strong answer covers

Common mistakes