Software Design

Token Bucket Rate Limiting with Redis

UML Sequence Diagrams · made in Skemio

Sequence diagram of Redis token bucket rate limiting showing atomic Lua evaluation, HTTP 429 rejection, and successful request forwarding to core backend.
Sequence diagram of Redis token bucket rate limiting showing atomic Lua evaluation, HTTP 429 rejection, and successful request forwarding to core backend.

What it shows

  • Redis stores token counts and timestamps in a single atomic hash structure
  • Atomic Lua scripts calculate refill math dynamically during request arrival
  • Exceeded limits return 429 Too Many Requests with Retry-After header values

The takeaway

Compute refills lazily inside Redis Lua scripts instead of running background timers.

More uml sequence diagrams