Question #43 of 60•Scaling•Medium• ~3 min read

How do Leaky Bucket, Token Bucket, and Fixed Window Rate Limiting algorithms compare?

Executive Takeaway

Analyze memory footprints, burst handling capabilities, and implementation complexity across rate limiting algorithms.

Architectural Breakdown & AnalysisFAANG Aligned

Rate limiters protect infrastructure using different traffic shaping algorithms.

AlgorithmHandles Traffic Bursts?Memory FootprintImplementation Complexity
Token BucketYes (up to bucket capacity)Low (Tokens + LastRefillTime)Simple
Leaky BucketNo (Smooths output rate)Low (FIFO Queue)Medium
Fixed WindowYes (Resets per window)Extremely Low (Counter integer)Simple
Sliding Window LogYesHigh (Stores timestamps)Complex

Algorithm Choice Guidelines

  • Use Token Bucket for general API rate limiting where brief user bursts are acceptable.
  • Use Leaky Bucket when downstream services require smooth, non-bursty ingress rates.
NOTE — Industry Standard

Token Bucket powers rate limiters in Nginx, AWS API Gateway, and Guava RateLimiter.

Previous QuestionWhat are the trade-offs of Event Sourcing vs CQRS (Command Query Responsibility Segregation)?Next Question How do Database Deadlocks occur and how do engines detect and resolve them?

Continue Learning on Being SDE

Explore deep-dive system architecture modules, low-level object-oriented designs, and interview cheat sheets.