ENES

Rate limiting

Capping how many requests someone can make in a given time window.

Many requests arrive at a gate that lets through five per second to a server; the extra ones bounce back with the code 429

Rate limiting is a rule like "at most 100 requests per minute per user" enforced by a server or an API. Requests under the limit go through normally. Requests over it are rejected, usually with the HTTP status 429 Too Many Requests and often a Retry-After header that says when to try again.

It protects in several directions at once. It slows down attacks that rely on volume, like a brute-force attack on a login form or a scraper copying a whole catalog. It keeps one buggy script or greedy customer from eating the capacity everyone shares. And it is how paid APIs enforce their plans: the free tier gets fewer calls per hour than the paid one, counted per API key.

Under the hood there are a few classic algorithms. A fixed window counts requests per calendar minute. A sliding window smooths out the burst at the edge of each minute. A token bucket refills a stash of tokens at a steady rate and lets each request spend one, which allows short bursts but caps the average. Limits can be keyed by user, by API key or by IP address. On its own it does not stop a large DDoS, whose traffic comes from thousands of addresses, but it is a cheap first line of defense.

Keep in mind

Go deeper

Related terms

More in Security