System Design

Token Bucket Rate Limiter with Redis

System Design diagram · made in Skemio

Diagram of an API Gateway using an atomic Redis Lua script to enforce token bucket rate limiting before passing traffic to backend services.
Diagram of an API Gateway using an atomic Redis Lua script to enforce token bucket rate limiting before passing traffic to backend services.

What it shows

  • Token buckets allow controlled bursts while capping sustained throughput.
  • Atomic Redis Lua scripts eliminate read-modify-write race conditions.
  • Refill calculations happen lazily on requests without background workers.

The takeaway

Run rate limiting checks inside Redis Lua scripts to stay thread-safe and fast.

More system design diagrams