Yashotantra Academy logo

4 · Performance & Fault Tolerance

7. Rate Limiting, Throttling & Circuit Breakers

Token bucket, leaky bucket, sliding window counters, and cascading failure containment.

10 min read · 3 MCQs

Rate Limiting Algorithms

Token Bucket: Tokens accumulate in a bucket at a fixed rate; requests consume tokens; permits bursts up to bucket capacity. Leaky Bucket: Requests enter a queue and process at a strictly constant rate, smoothing traffic spikes. Sliding Window Log/Counter: Tracks timestamped requests in memory to enforce precise limits over rolling time boundaries.

Distributed Rate Limiting with Redis

In multi-instance microservices, centralized rate limits use Redis with atomic Lua scripts. Using Redis pipelines or Redis cells avoids race conditions and network round-trips when checking and decrementing client IP quotas.

Circuit Breakers (Closed, Open, Half-Open)

To prevent cascading failures when a downstream dependency is failing, a circuit breaker wraps calls: Closed (normal operations), Open (dependency has failed threshold; calls fail immediately without touching the downstream service), and Half-Open (allows trial requests through to test recovery).

Chapter quiz

3 questions · pass mark 75%
  1. 1. Which rate limiting algorithm natively allows controlled bursts of requests up to a maximum capacity?

  2. 2. What is the primary purpose of a Circuit Breaker in microservices?

  3. 3. When a circuit breaker is in the 'Half-Open' state, it: