Problem
Without rate limiting, malicious or accidental high-volume traffic can overwhelm services, cause cascading failures, and degrade availability for all users. Uncontrolled requests consume resources and increase costs.
Also known as: rate-limit, throttling
Control the rate of requests to a service or API to prevent abuse, ensure fair usage, and protect against denial-of-service attacks.
Without rate limiting, malicious or accidental high-volume traffic can overwhelm services, cause cascading failures, and degrade availability for all users. Uncontrolled requests consume resources and increase costs.
Control the rate of requests to a service or API to prevent abuse, ensure fair usage, and protect against denial-of-service attacks.
Tokens are added to a bucket at a steady rate. Each request consumes one token. If the bucket is empty, the request is rejected. Allows brief bursts up to the bucket capacity. Example: 100 tokens per minute, bucket size 20.
A fixed-size window slides over time. Counts requests within the current window. The window slides forward, old requests drop off. More precise than fixed window. Example: 100 requests per 60-second sliding window.
Counter resets at fixed intervals (e.g., per minute). Simple to implement and understand. Can be gapped at window boundaries. Example: 100 requests per minute, counter resets at :00.
Retry-After header| Category | Assessment | |----------|-----------| | Infrastructure | Low — Redis or in-memory counter | | Operational | Low — once configured, self-regulating | | Cognitive | Medium — choosing and tuning the right algorithm |
Low — Redis or in-memory counter
Low — once configured, self-regulating
Medium — choosing and tuning the right algorithm
Counter overflow: Metrics become inaccurate
Single point of failure: Local counters in single-instance deployments
Incorrect window boundaries: Gapping at interval boundaries
Bypassed limits: Clients rotating IPs or using proxies