Simulate second-by-second API traffic spikes through a Token Bucket rate limiter: calculate accepted requests (HTTP 200), throttled HTTP 429 Too Many Requests drops, bucket depletion time, `Retry-After` guidance, and ready-to-paste NGINX limit_req_zone config.
| Second | Incoming Load | Start Tokens | Accepted (200) | Rejected (429) |
|---|
nodelay + HTTP 429)
Token Bucket Math, Burst Buffers & HTTP 429 Semantics
Rate limiting is your frontline circuit breaker when runaway client retries or misbehaving AI agents hammer downstream databases. Based on NGINX ngx_http_limit_req_module and HTTP congestion semantics in IETF RFC 9110 (Retry-After), bucket depth at step $t$ updates as:
Setting limit_req_status 429; prevents NGINX from emitting default HTTP 503 codes—which load balancers and health checks often misclassify as origin failure. Roughly 1 MB of NGINX shared memory holds ~16,000 IPv4 client states (~64 bytes per slot).
Production Rate Limiting Algorithm Trade-offs
| Algorithm | Common Implementations | Memory Footprint | Primary Caveat |
|---|---|---|---|
| Token Bucket | AWS API Gateway, NGINX, Stripe | O(1) · 2 scalars per key | Allows brief downstream spikes up to `burst` |
| Leaky Bucket / GCRA | Envoy, Redis Cell, strict edge shaping | O(1) · 1 timestamp (TAT) | Can slow legitimate multi-call SPA loads |
| Fixed Window Counter | Redis `INCR` + `EXPIRE` | Very low | 2x edge burst at window boundary (:59 -> :00) |
| Sliding Window Log | Auth & payment anti-fraud endpoints | High (Sorted Set logs) | RAM balloons under sustained DDoS floods |
Frequently Asked Questions
How large should burst be relative to sustained rate?
For browser apps firing 6–12 parallel calls on initial render, set `rate` to your sustainable origin throughput and give `burst` 2x–4x headroom with `nodelay` so valid bursts don't stall on queues. Calculate safe origin RPS first in our Little's Law RPS capacity calculator and size backing Redis counters in our Redis / Valkey RAM sizer.
Should HTTP 429 responses always include Retry-After?
Yes—returning RFC 9110 `Retry-After` seconds lets compliant SDKs pause deterministically before exponential jitter retries. Explore more backend utilities in our Syncroma Tools directory.