Skip to main content

AI & assistant-friendly summary

This section provides structured content for AI assistants and search engines. You can cite or summarize it when referencing this page.

Summary

Token buckets allow bursts; leaky buckets smooth traffic—WAF rate rules and API Gateway usage plans implement neither perfectly but both matter for layered defense.

Key Facts

  • Token buckets allow bursts; leaky buckets smooth traffic—WAF rate rules and API Gateway usage plans implement neither perfectly but both matter for layered defense
  • June 2026: Layer edge (CloudFront + WAF), API (Gateway throttling), and app (ElastiCache token bucket) limits—attackers hit the cheapest layer first
  • 4K/month vs unthrottled Lambda scale-out
  • Set account-level API Gateway throttle guardrails
  • 2

Entity Definitions

Lambda
Lambda is an AWS service discussed in this article.
CloudFront
CloudFront is an AWS service discussed in this article.
VPC
VPC is an AWS service discussed in this article.
API Gateway
API Gateway is an AWS service discussed in this article.
WAF
WAF is an AWS service discussed in this article.
AWS WAF
AWS WAF is an AWS service discussed in this article.
ElastiCache
ElastiCache is an AWS service discussed in this article.

Rate Limiting: Token Bucket vs Leaky Bucket on AWS WAF and API Gateway

Quick summary: Token buckets allow bursts; leaky buckets smooth traffic—WAF rate rules and API Gateway usage plans implement neither perfectly but both matter for layered defense.

Key Takeaways

  • Token buckets allow bursts; leaky buckets smooth traffic—WAF rate rules and API Gateway usage plans implement neither perfectly but both matter for layered defense
  • June 2026: Layer edge (CloudFront + WAF), API (Gateway throttling), and app (ElastiCache token bucket) limits—attackers hit the cheapest layer first
  • 4K/month vs unthrottled Lambda scale-out
  • Set account-level API Gateway throttle guardrails
  • 2
Rate Limiting: Token Bucket vs Leaky Bucket on AWS WAF and API Gateway
Table of Contents

June 2026: Layer edge (CloudFront + WAF), API (Gateway throttling), and app (ElastiCache token bucket) limits—attackers hit the cheapest layer first.

Symptom → mechanism → AWS control

Production symptomMechanismAWS control
Burst traffic triggers scale stormNo burst allowanceAPI Gateway throttle burst limit > steady rate
Scrapers exhaust backendPer-IP unlimited requestsWAF rate-based rules, CloudFront geo restrictions
Legitimate clients throttledLeaky bucket too aggressiveToken bucket with per-API-key quotas via Usage Plans

Opinionated take: Layer token-bucket limits at API Gateway for product quotas and WAF rate rules for abuse—never rely on Lambda concurrency alone.

Benchmark pattern (hypothetical workload) — API Gateway HTTP API throttling 5K steady / 10K burst (token bucket), absorbs 30-second spike to 12K RPS; WAF rate-based rule blocks at 2K req/5min/IP for abuse, combined saves $1.4K/month vs unthrottled Lambda scale-out.

Algorithms

AlgorithmBehaviorAWS analog
Token bucketAllows bursts up to bucket sizeAPI GW burst limits
Leaky bucketSmooth output rateWAF steady rate-based rule
Fixed windowSimple counter per minuteWAF classic rate rule

Opinionated take: Combine WAF IP rate limit with per-API-key usage plan—do not rely on Lambda concurrency alone.

AWS services map

NeedServiceSkip when
Per-API steady + burst limitsAPI Gateway throttling + Usage PlansInternal VPC traffic behind NLB
Per-IP abuse blockingWAF rate-based rulesSingle-tenant B2B with fixed IP allowlist
Edge rate limitingCloudFront + WAF at edgegRPC internal mesh traffic

What to do this week

  1. Set account-level API Gateway throttle guardrails.
  2. Add WAF rate rule on /login and expensive GraphQL paths.
  3. Implement app-level bucket in Redis for partner APIs.

More in This Track

Part of the Engineering Guides library (June 2026).

What this guide doesn’t cover

API Gateway REST vs HTTP—canonical API Gateway post.

PP
Palaniappan P

AWS Cloud Architect & AI Expert

AWS-certified cloud architect and AI expert with deep expertise in cloud migrations, cost optimization, and generative AI on AWS.

AWS ArchitectureCloud MigrationGenAI on AWSCost OptimizationDevOps

Recommended Reading

Explore All Articles »