System Design Fundamentals
Back to Reliability and Operations

Rate Limiting

Protect your API from abuse and overload. Token bucket, leaky bucket, sliding window — and where to put the limiter. FIND_VIDEO: search 'rate limiting algorithms system design' — recommended channel: ByteByteGo / Hussein Nasser. Aim for 10 min or under.

8 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. Rate Limiting Requirements — Covers system protection objectives, fair access goals, and core non-functional latency and availability constraints.
  2. Fixed Window Counting — Explains how the basic fixed-time interval counter operates and tracks request limits.
  3. Distributed Storage Needs — Demonstrates why multi-server architectures require a centralized in-memory datastore like Redis.
  4. Window Boundary Flaw — Analyzes how bursts timed around window reset boundaries double the allowed request volume.
  5. Token Bucket Algorithm — Introduces bucket capacity and refill rate mechanics to support bursts while maintaining sustained limits.
  6. Architectural Placement — Evaluates trade-offs between client-side, server-side, and API Gateway middleware rate limiting.
  7. Middleware Request Lifecycle — Traces end-to-end request interception, cache validation, and HTTP 429 response handling.
  8. Atomic Redis Operations — Details how Redis Lua scripts eliminate race conditions during concurrent counter increments.
PDF notes

Frequently asked questions

Why is client-side rate limiting insufficient on its own?

Client-side limiting cannot protect servers against malicious actors, buggy clients, or forged requests that bypass client controls.

What happens if the central Redis rate limiter instance goes down?

Systems typically configure a fail-open strategy to maintain availability, logging an alert while allowing traffic to pass downstream.

How do you choose bucket capacity versus refill rate in Token Bucket?

Set refill rate to the maximum sustained RPS backend services can support, and set capacity to the maximum acceptable burst size.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.