Why it matters

Rate limiter design is classic problem. Understanding shapes many services.

Advertisement

The architecture

Token bucket: refill at rate, burst up to capacity.

Sliding window: exact count in window.

Rate limiter approachesToken bucketburst + rateSliding windowexact countRedis backenddistributed stateFixed window has 2x-limit boundary issue; sliding fixes
Rate limiter algorithms.
Advertisement

How it works end to end

Redis: atomic increment + TTL.

Lua scripts: atomic multi-op.

Distributed: consistent hashing for scale.

Return 429 with retry-after.