Fixed window vs token bucket
Login API rate limiting, simulated in a terminal (Python, rich)
A live terminal demo of a login API under a password-guessing attack, defended by two different rate limiters.
The detail: a fixed window counter gives its whole allowance back at the minute boundary. Aim for that instant and a limit of 10 logins per minute lets 20 through in 2 seconds. A token bucket never resets all at once, so the same attack gets 10.
| Limiter | Attack | Let through |
|---|---|---|
| Fixed window | steady, one minute | 10, holds |
| Fixed window | boundary burst | 20 in 2 s, 2× the limit |
| Token bucket | boundary burst | 10 in 2 s, holds |
| Counter per server | 30 tries, 10 servers | 30, 3× the limit |
| Shared Redis counter | 30 tries, 10 servers | 10, holds |
Nothing on screen is faked: every 200 OK and 429 is the return value of the limiter code.