TomoLink
CompaniesMetaSystem DesignDesign a Rate Limiter
System Design
MediumInfrastructure

Design a Rate Limiter

40 minsrate-limitingdistributed-systemsredis
40 mins
1 sections
rate-limiting, distributed-systems

What is a Rate Limiter?

Purpose

A rate limiter controls the rate of requests that a client can send to an API. It prevents DoS attacks, reduces costs, and ensures fair usage.

Common Rate Limiting Algorithms

1. Token Bucket

  • Tokens are added at a fixed rate
  • Each request consumes one token
  • Allows burst traffic up to bucket capacity

2. Leaking Bucket

  • Requests are added to a queue (bucket)
  • Processed at a fixed rate
  • Overflow requests are dropped

3. Fixed Window Counter

  • Time divided into fixed windows
  • Counter reset at the start of each window
  • Simple but can allow 2x the rate at window boundaries

4. Sliding Window Log

  • Tracks timestamps of all requests
  • Remove entries older than the window size
  • Accurate but memory-intensive

5. Sliding Window Counter

  • Hybrid of fixed window + sliding window
  • Approximates sliding window with less memory
Design a Rate Limiter [Medium] | Meta System_design | TomoLink