Init guide environment...
Tokens refill at a steady rate. Each request needs a token. Allows controlled bursts.
Requests queue up and are processed at a constant rate. Excess overflow is dropped.
Time split into windows with a request counter. Counter resets at each boundary.
Sliding window log tracks timestamps; counter uses weighted averages for accuracy.
High-level request flow through a rate limiter
flowchart TD
A["Client Request"] --> B{"Rate Limiter"}
B -->|"Within Limit"| C["✅ Forward to Server"]
B -->|"Exceeds Limit"| D["❌ 429 Too Many Requests"]
C --> E["Server Response"]
D --> F["Retry After Header"]Watch how each algorithm handles incoming requests
| Algorithm | Throughput | Memory | Burst Handling | Accuracy | Best Use Case |
|---|---|---|---|---|---|
| Token Bucket | API gateways, CDNs | ||||
| Leaking Bucket | Traffic shaping | ||||
| Fixed Window | Simple APIs | ||||
| Sliding Log | Strict rate limits | ||||
| Sliding Counter | Balanced APIs |