post://api-rate-limiting-token-vs-leaky-bucket

API Rate Limiting Strategies: Token Bucket vs Leaky Bucket

author: Swadhin Biswas read: 1 min
System DesignBackendPerformance
API Rate Limiting Strategies: Token Bucket vs Leaky Bucket

API Rate Limiting Strategies

Rate limiting protects both infrastructure and user experience.

{
  "type": "line",
  "data": {
    "labels": ["0s", "10s", "20s", "30s", "40s"],
    "datasets": [
      { "label": "Requests", "data": [20, 30, 120, 40, 35], "borderColor": "#84d5ea" },
      { "label": "Allowed", "data": [20, 30, 60, 40, 35], "borderColor": "#7aa2ff" }
    ]
  }
}

Distributed counters should use atomic operations and consistent window semantics.