Skip to main content

Rate Limiting

Difficulty: Medium | Topic #15

What to Learn

Token bucket, leaky bucket, and sliding window algorithms; distributed rate limiting with Redis (atomic Lua scripts), rate limiting at the API gateway vs per-service, handling burst traffic.

Resources

Covered by Problems

ProblemDifficultyLink
URL Shortener/BitlyEasy
Rate LimiterMedium
LLM Service (ChatGPT)Hard

Key Concepts to Master

  • Token bucket (allows bursts up to capacity) vs leaky bucket (constant output rate)
  • Sliding window log vs sliding window counter tradeoffs
  • Redis INCR + TTL for distributed counters
  • Lua scripts for atomicity in Redis
  • Rate limiting at the edge (API gateway) vs per-microservice