Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
All topics/Rate Limiting & Throttling
RELIABILITY, SECURITY & CASE STUDIES · SUBTOPIC

Distributed Rate Limiting & Leaky Bucket

Coordinate limits across dozens of API gateway pods and smooth outbound bursts.

IntermediatePart of Rate Limiting & Throttling
Practice in AI HLD
Subtopics in Rate Limiting & Throttling (2)
OverviewToken Bucket & WindowsDistributed & Leaky Bucket

In plain words

Leaky Bucket drips water out of a funnel at one steady speed even if someone dumps a whole pitcher in - great for protecting slow downstream APIs. Distributed rate limiting shares one Redis cluster so users can’t multiply their quota by hitting 10 gateways.

Think of it like…

Funnel dripping smoothly into a bottle (Leaky Bucket) + shared scoreboard across every stadium gate (Redis).

Loading interactive diagram
Loading interactive exercise

Theory & how it works

Fail-open vs. Fail-closed when Redis is unreachable

For normal API traffic, fail-open (allow requests or apply a loose local memory cap) so a Redis hiccup doesn’t take your whole product offline. For security-critical endpoints like /login or /otp/verify, fail-closed or enforce strict local IP limits to block credential-stuffing attacks.

Key points & practical guide

Summary checklist

  • Leaky Bucket smooths bursty traffic into a constant outflow rate
  • Rate limit by User/API-Key for authenticated routes, IP for anonymous routes
  • Decide explicit fail-open vs. fail-closed behavior per endpoint

When to use it

  • Protecting third-party webhooks/APIs with strict RPS caps and multi-node gateways

Watch out for

  • Storing per-gateway counters in local RAM only - 20 gateways gives every attacker 20× the limit!

Quick check

Loading quiz
Previous subtopic
Token Bucket vs. Sliding Window Algorithms
Back to overview
Full Rate Limiting & Throttling Lesson