30 mins|Advanced

Distributed Rate Limiter & Token Bucket

Architect a distributed, multi-region rate limiter balancing low latency, precision, and blast-radius resilience.

Core Framework

Rate limiters protect infrastructure from cascading overload, malicious attacks, and noisy tenant starvation. In Big Tech system design rounds (Google L6, Atlassian M60), candidates are evaluated on algorithm choice (Token Bucket vs Sliding Window Log), distributed synchronization (Redis clusters vs local in-memory with batch sync), and graceful degradation during cache failures.

Key Principles & Mental Models

1Token Bucket vs Sliding Window

Token Bucket allows burst traffic up to bucket capacity and requires minimal memory (2 numbers per client). Sliding Window Counter prevents 2x burst across window boundaries but has slightly higher write overhead.

2Distributed State vs Local Caching

A centralized Redis tier introduces 2–5ms network latency per API request. A hybrid architecture uses local in-memory token buffers with asynchronous Redis sync for non-financial rate limits.

3Fail-Open vs Fail-Closed Policy

If the distributed rate limiting tier crashes, tier-1 critical paths (e.g. login, payment checkout) must fail open to avoid customer downtime, while expensive third-party webhooks fail closed.

Do's and Don'ts

Do This
  • Use Redis Lua scripts to execute get-and-decrement operations atomically.
  • Define distinct rate limits by client identity: per API key, per IP, and per tenant tier.
✕Avoid This
  • Issue multiple sequential Redis GET and SET commands that suffer from race conditions.
  • Apply one global rate limit that allows one noisy customer to exhaust capacity for all tenants.
← Back to Catalog