ufraan
← Back

Distributed Rate Limiter

Token bucket rate limiter with sliding window and distributed coordination across nodes.

TypeScriptRedisRate LimitingAlgorithms
Oct 2024GitHub

Implemented sophisticated rate limiting supporting multiple algorithms: token bucket, sliding window, and leaky bucket. Uses Redis for distributed coordination across service instances to enforce global rate limits. Handles complex scenarios like burst capacity, per-user limits, and time-based quota resets. Achieves microsecond response times with minimal overhead through careful algorithm design and caching strategies.

Rate limiter showing tokens being added and consumed
Rate limiter showing tokens being added and consumed

The system supports hierarchical limits—global, per-tenant, and per-endpoint. Redis scripts ensure atomic operations without race conditions. Metrics are exposed for monitoring, showing current usage, rejections, and quota utilization to help identify bottlenecks.