Distributed token bucket with consistency hazards.
Rate Limiter (Deep): distributed token bucket with consistency hazards
compose the pieces into a design story
Lua atomicity vs network roundtrips.
Building a global rate limiter requires atomic state at scale. Redis with Lua scripts implements token bucket exactly; sharding by key avoids hot keys. Sliding-log algorithms give precise smoothing at higher cost.
Lua script: atomically read tokens, compute refill, decide allow/deny.
Per-key shard handles high cardinality; per-host limits aggregate.
Clock skew across edges causes drift; align with NTP and use server time.
Implement 100 req/min per API key.