Rate Limiting
Subject: Computer and Technology noun /ˈreɪt ˌlɪm.ɪ.tɪŋ/ 1 definition
- api-design
- traffic-management
- network-security
- distributed-systems
-
Definition (noun)
Entry #77 · UpdatedRate Limiting is a traffic-control mechanism used in APIs, web services, and computer networks to cap the rate at which a client, user, or IP address can submit requests or consume resources over a given interval. By tracking request frequency against predefined thresholds, an application or intermediary gateway either delays, throttles, or rejects excess traffic—commonly returning an HTTP
429 Too Many Requestsstatus with aRetry-Afterheader. Its core purpose is to protect backend stability, mitigate brute-force and denial-of-service attacks, prevent cascading failures, and ensure fair resource sharing across consumers.Common Forms
Token Bucket: Refills a virtual bucket with tokens at a fixed rate up to a maximum capacity, consuming one token per request so brief traffic bursts are permitted while keeping the long-term average rate bounded.
Leaky Bucket: Queues incoming requests in a fixed-size buffer and drains them at a constant outflow rate, smoothing spiky traffic into a steady stream and dropping requests when the queue overflows.
Fixed Window Counter: Tracks request counts within discrete, aligned time intervals (such as per minute) and resets at each boundary, offering simple implementation at the cost of potential double-burst spikes near window edges.
Sliding Window: Evaluates request timestamps across a rolling time span—using either sorted request logs or weighted counters from the previous interval—to enforce smooth, accurate limits without boundary-spike artifacts.
Example
An authentication service configures an API gateway rate limit of 5 login attempts per minute per IP address using a sliding window counter in Redis. When a credential-stuffing script sends 40
POST /loginrequests in three seconds from a single IP, the gateway processes the first 5 attempts and immediately rejects the remaining 35 with HTTP429 Too Many Requests, keeping database load flat for legitimate users.