Rate limiting controls frequency, not total resource safety
Rate limiting defines how often a client can perform an operation within a period. Redis documents limits per user, IP, API key, tenant or other dimensions, while OWASP recommends tuning limits to the specific endpoint and business need. [4][12]
OWASP API4:2023 shows that request-rate limits alone do not solve unrestricted resource consumption. APIs should also bound payload sizes, batched operations, returned records and spending on external providers. [12]
429 Too Many Requests and Retry-After
RFC 6585 defines 429 Too Many Requests for cases where a client has sent too many requests in a given time. The response may include Retry-After to tell the client how long to wait. [1]
RFC 9110 defines Retry-After as either an HTTP-date or a number of delay seconds. [2]
RFC 6585 deliberately does not define how the origin server identifies the user or counts requests. Limits may apply per resource, across a server, across a server set or to different client identities. [1]
Fixed Window: the simplest time counter
Fixed Window divides time into discrete non-overlapping intervals, such as 60 seconds. Each request increments the current counter, and the next window starts with a fresh count. [6]
Redis shows implementations with INCR and EXPIRE. The update should be atomic to avoid cases where a counter increments but expiry is never set. [7][8]
Its main weakness is the boundary burst. Redis notes that traffic at the end of one window and the start of the next can allow close to twice the nominal rate over a short interval. [5][6]
Sliding Window Log: accuracy at a memory cost
Sliding Window Log stores a timestamp for every request in the current moving window. On each request, expired entries are removed and the remaining entries are counted. [6]
Redis classifies it as exact and free from fixed-window boundary bursts, but with O(n) memory because stored entries grow with the number of requests in the active window. [5][6]
It is useful for high-value endpoints or when a precise request trail matters, but can be much more expensive at very high request volume.
Sliding Window Counter: a practical compromise
Sliding Window Counter does not keep every request timestamp. It combines counters from adjacent windows to estimate use over the current moving interval. [6]
Redis describes it as near-exact, with smoother window boundaries and much lower memory use than Sliding Window Log. [5][6]
It is a good general-purpose choice when per-request precision is not required but Fixed Window boundary behavior is too coarse.
Token Bucket: controlled bursts
Token Bucket maintains a bucket with a maximum capacity. Tokens are replenished at a fixed rate and each operation consumes a token. A request is accepted when enough tokens are available. [5]
Accumulated tokens allow a short burst, while the refill rate limits sustained traffic over time. [5]
The token-bucket model has a long history in network traffic control. RFC 2697 and RFC 2698 define token-bucket-based traffic meters, although they are not HTTP rate limiting specifications. [10][11]
Leaky Bucket: policing and shaping are not the same
The term Leaky Bucket is used for more than one behavior. Redis describes a policing variant as exact with no bursts, where traffic beyond the configured rate is rejected. [5][6]
NGINX also describes limit_req as using the leaky bucket method, but by default excess requests inside the configured burst can be delayed to maintain the configured rate. Requests beyond the burst are rejected. [9]
When comparing implementations, check whether excess traffic is rejected immediately or queued and smoothed.
Choosing an algorithm
| Algorithm | Memory | Accuracy | Burst behavior | Best fit |
|---|---|---|---|---|
| Fixed Window | 1 counter per window | Approximate at boundaries | Boundary burst possible | Simple API limits |
| Sliding Window Log | O(n) timestamps | Exact | No boundary burst | High-value APIs and audit |
| Sliding Window Counter | Small aggregated counters | Near-exact | Smoothed boundaries | General-purpose APIs |
| Token Bucket | Small bucket state | Exact for the model | Controlled bursts | Bursty traffic |
| Leaky Bucket | Small state / queue depending on implementation | Exact for the model | None or smoothed | Steady-rate enforcement |
Redis compares Fixed Window Counter, Sliding Window Log, Sliding Window Counter, Token Bucket and Leaky Bucket across memory, accuracy and burst behavior. [5][6]
Token Bucket fits APIs that should tolerate short bursts. Sliding Window Counter is a broad compromise. Sliding Window Log fits cases where exactness matters more than memory, while Leaky Bucket policing fits strict no-burst enforcement. [5]
What should be limited: IP, user, API key or tenant
| Limit key | Advantage | Risk |
|---|---|---|
| IP | Works before sign-in and at the edge. | NAT can group many users; proxies and botnets evade it. |
| User / account | Protects one account regardless of source. | Requires reliable user identity. |
| API key | Good for machine-to-machine integrations. | A client may have several keys if policy allows it. |
| Tenant / organization | Controls a shared organization budget. | One active user may consume quota for others. |
| Endpoint / operation | Allows stricter limits for expensive operations. | Does not itself provide fair usage between clients. |
Redis notes that quotas can be keyed by user, IP, API key, tenant, model or another dimension. The key determines whether the limit protects an account, integration, organization or the whole service. [4]
OWASP recommends not relying only on IP. For login, its bot-management guidance proposes separate per-username and per-IP limits because a single combined IP+username bucket can allow one source to try the threshold against many usernames. [13]
Distributed proxy networks can also keep per-IP traffic low, so per-IP throttling should be only one layer against credential stuffing. [14]
Distributed rate limiting: local counters are not enough
When an API runs on multiple instances behind a load balancer, process-local counters do not provide one global limit because the same client can hit different instances. Redis documents this limitation directly. [4]
A shared store such as Redis lets all instances make allow/deny decisions against the same state. Atomic operations are important so concurrent requests cannot double-spend tokens or lose counter updates. [4][5][8]
Gateway or application layer
An edge or API-gateway limiter can reject traffic before it reaches expensive services and can apply broad shared policies. An application-level limiter has richer access to authenticated identity, business context and operation cost.
OWASP recommends layered defenses: basic controls at the edge, identity-aware and behavioral limits in the application, and business-level anomaly detection deeper in the system. [13]
A production system can therefore apply multiple simultaneous limits, such as a tenant-wide quota plus a stricter login or report-generation limit.
Not every request should cost one unit
Counting every request as one unit may be insufficient when operations have very different costs. OWASP API4 highlights CPU, memory, storage, batch size, returned records and external-service spending. [12]
The current IETF RateLimit headers draft includes quota units so a policy can express units other than raw request count. The document is still an Internet-Draft, not a published RFC. [3]
A limiter can therefore charge more units for expensive operations if that policy is consistent and documented for clients.
RateLimit headers in 2026: standards status matters
| Field / status | Meaning in 2026 |
|---|---|
| 429 Too Many Requests | RFC standard: the client sent too many requests in a given time. |
| Retry-After | RFC standard: HTTP-date or number of seconds before retry. |
| RateLimit-Policy | Defined in an active IETF Internet-Draft, not a final RFC. |
| RateLimit | Defined in an active IETF Internet-Draft, not a final RFC. |
| X-RateLimit-* | Commonly deployed, but naming and semantics are inconsistent. |
As of May 2026, active Internet-Draft draft-ietf-httpapi-ratelimit-headers-11 defines RateLimit-Policy and RateLimit fields to advertise quota policy and current service limits. [3]
It is still an IETF Internet-Draft and should not be presented as a finalized RFC. [3]
The draft also documents commonly deployed X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset headers and interoperability problems caused by inconsistent names and semantics. [3]
Rate limiting login and abuse
OWASP recommends rate limiting as a foundational control against automation, credential stuffing and abuse, but not as the only defense. [13][14]
For login, consider at least independent per-account and per-IP or source limits. OWASP also highlights MFA, breached-password checks, selective CAPTCHA and anomaly monitoring. [13][14]
Limits should be temporary and risk-aware. Overly aggressive account blocking can itself become a denial-of-service vector against legitimate users.
A practical rate limiter architecture
For one simple API, Fixed Window may be sufficient. A multi-instance API needs shared state or a gateway layer, and state updates should be atomic. [4][7][8]
A sound design defines the algorithm, limit key, quota unit, short- and long-term limits, exceed behavior and client-facing response. Choosing Token Bucket over Sliding Window does not fix poor client identity or an unbounded cost per request. [12][13]
- Start by identifying the resource you are protecting: CPU, database capacity, third-party API cost, an account or fair usage.
- Separate limits for cheap and expensive endpoints.
- Do not rely only on per-IP limits for authenticated users.
- Use shared state or a gateway in multi-instance systems.
- Keep read-decide-update atomic.
- Return 429 when the semantics are too many requests and consider Retry-After.
- Monitor rejected requests, hot keys and impact on legitimate clients.
- Test boundary bursts, shared-store failure, clock behavior and recovery after limiter outages.
