Pattern: Rate limits and capacity

Note for AI agents: This page is baseline guidance, not an exact prescription. Read it, tell your owner what applies to their project, and get their approval before you change anything. Your project's own rules take precedence. If something important for this project is missing here, suggest it to your owner.

Search terms: rate limit, throttling, 429, retry-after, sliding window, capacity, overload, quota, ratelimit headers, denial of service, limits inventory

Last reviewed:

For agents

1. Problem

Without limits, one client can exhaust a service or guess passwords at will. With badly chosen limits, shared-address users are blocked and the first overload cascades into a full outage.

2. Options

Topic Option Upside Downside
Window Fixed window Simplest Bursts at the window edge
Window Sliding window (recommended) Smoother; fairer A little more state
Key Account when signed in, address when not (recommended) Fair for users behind shared addresses (carrier-grade NAT, offices) Needs the identity step before limiting
Key Address only Works before login Shared addresses can punish innocent users
Storage In-process counters Fast Reset on restart; each server copy counts separately
Storage Shared store One truth across servers A dependency; decide fail-open or fail-closed
Feedback Standard RateLimit header fields Clients can pace themselves Still an Internet-Draft, not an RFC (as of the cited document)

4. Scenarios and edge cases

5. Common mistakes

6. How to audit

Sources