02 / JAVA · SPRING · REDIS
Distributed
Token Bucket
LIMITERINPUTCORESTATEOUTPUTTRACE
Make rate limiting atomic.
The limiter is designed for concurrent application instances where a local counter is not enough. Redis becomes the shared state, while a Lua script keeps refill, consume and retry calculation together.
The token-bucket model makes the behaviour intuitive: requests spend tokens, tokens refill over time, and exhausted buckets return a predictable retry path. The design keeps the decision close to the shared state rather than scattering it across instances.
Token flow
REQUESTS → ATOMIC LUA → SHARED BUCKET
PREMIUM · 20 TOKENS
429 · RETRY-AFTER
Requests consume shared tokens; refill and consumption happen atomically.
1ATOMIC LUA OPERATION
∞CONCURRENT INSTANCES
429EXPLICIT BACKPRESSURE
NEXT CASE STUDYBanking Microservices ↗