Rate Limiting & Token Buckets
Protect downstream APIs and services from Denial-of-Service spikes using Token Bucket and Sliding Window Log algorithms.
๐ก Why It Matters
Uncontrolled API traffic can crash databases, exhaust connection pools, and burn cloud infrastructure budgets.
๐ Real-World Production Usages & Examples
GitHub API Tier Limiting
Scenario: Enforcing 5,000 requests/hour for authenticated users.
โ When to Use
- โขPublic API endpoints exposed to third-party developers.
- โขAuthentication / login routes.
- โขCostly AI LLM inference endpoints.
โ When NOT to Use
- โขInternal microservice IPC where mesh circuit breaking is preferred.
๐ Core Architecture & Rules
- 1Token Bucket fills tokens at a constant rate; permits short bursts.
- 2Sliding Window Counter combines window counters with weighted overlap percentages.
โ๏ธ Architectural Trade-Off Analysis
Algorithm Selection
โ ๏ธ Failure Modes & Mitigations
Race Condition in Counter
Non-atomic counter updates across gateway nodes.
๐ ๏ธ Example Usages
Reviewed practical implementations and concrete code walkthroughs for Rate Limiting & Token Buckets.
Atomic Redis Lua Token Bucket Rate Limiter
Applies the Token Bucket design pattern atomically across distributed gateway instances using Redis Lua scripts.
โฌกExplore Related Concepts & Guides
Curated technical reading and direct concept relationships.
๐Core Implementation Guides & Patterns(3 resources)
Trace how Redis Event Reactor multiplexes thousands of concurrent TCP client connections through a single main thread loop, avoiding thread synchronization overhead.
Analyze how high-volume API gateways protect downstream microservices using distributed Token Bucket and Sliding Window Log algorithms in Redis.
๐ Related Concepts
Explore full connection graph โReady to apply Rate Limiting & Token Buckets?
Test your understanding with a short scenario about real system constraints and trade-offs.
