Token bucket smoothly absorbs bursts: bucket of N tokens refilling at R per second; each request consumes 1; reject if empty. Fixed-window counter resets every minute, allowing 2x the rate at the window boundary. Token bucket is the standard for protecting downstream quotas.
Redis Lua script for atomic refill+consume across replicas.
Per-user bucket key: rl:user:{user_id}; refill 60 tokens / minute.
Middleware returns 429 + Retry-After.
request -> bucket.consume()
if allowed: proceed
if empty: 429 + Retry-After
Token bucket for burst tolerance. Sliding window for fairness. Leaky bucket for stable rate.