Try
↑ ↓ move↵ openesc close

Interview prep / Rate limiting algorithms

Junior · Rate limiting algorithms · System design interview question

What does a rate limiter do, and where in a system would you put one?

Sketch your own answer first, then compare it with the one below.

A strong answer

A rate limiter caps how many requests a caller may make in a period of time. It checks each request against an allowance kept for that caller and rejects the ones over it. The caller can be a user, an API key, an address, a tenant, or a whole service.

It does two jobs. It protects a service from one caller who sends too much, by accident or on purpose. And it shares capacity out, so that one heavy caller cannot crowd everyone else out.

Common places are an API gateway or reverse proxy at the edge, a middleware layer inside a service, and the client side for calls to a paid or fragile dependency. Putting it early is cheaper, because a rejected request has used almost nothing. Putting it close to the resource is more accurate, because it knows what the resource can take.

Do not confuse this with load shedding. A limiter looks at the caller and enforces a promise made in advance. Shedding looks at the server's own state and reacts to overload. Most services need both.

Sources

Learn it by running it

The rate limiting algorithms lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms