bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/System Design/Design a Rate Limiter
System Design•Design a Rate Limiter

Design a Rate Limiter: Scaling

Design a distributed rate limiter that caps how many requests a client (API key / IP) can make per time window.

How to approach it

Scale by following the request path and fixing the first real bottleneck. Reads usually dominate, so caching and replication come first; writes and storage are handled by sharding on a high-cardinality key. Push slow, retryable work onto queues. Add infrastructure only where the numbers justify it.

Scaling decisions

AreaChoice
StoreCentralized Redis with atomic INCR + TTL (or a Lua script)
LatencyLocal token bucket with periodic sync to Redis
Hot keysShard counters / add jitter for very hot clients
FailureFail-open for availability or fail-closed for protection (policy)

Why

  • Store: shared state so all gateway nodes agree on the count
  • Latency: avoids a network hop per request at the cost of slight inaccuracy
  • Hot keys: prevents a single Redis key from becoming a bottleneck
  • Failure: decide what happens when the counter store is unreachable

Previous

Design a Rate Limiter: High-Level Architecture

Next

Design a Rate Limiter: Deep Dive