All posts
Internet Fundamentals

Rate Limiting: Token Buckets, Per-User Limits and Answering With 429

By

October 26, 2026

5 min read

Rate limits protect your service from abuse, your bill from runaway clients, and your users from each other. The algorithms (fixed window, sliding window, token bucket), where to enforce limits (edge, gateway, application), what to key them on, and how to tell clients to back off properly.

Internet Fundamentals
Rate Limiting
APIs
AWS WAF
Amazon API Gateway

The algorithms

Algorithm

How it works

Tradeoff

Fixed window

Count requests per minute; reset on the minute

Simple; allows double the rate across a window boundary

Sliding window

Count requests in the last N seconds

Smoother; slightly more state

Token bucket

Tokens refill at a steady rate up to a cap; each request spends one

Allows short bursts while holding the average; what API Gateway uses

Want a second opinion on this for your system?

Book a free 30-minute call. You'll leave knowing what we'd do first and roughly what it costs, whether or not you hire us.

Where to enforce

  • At the edge (AWS WAF rate-based rules, Cloudflare rules): per IP, cheap, stops floods before they reach you.

  • At the gateway (API Gateway usage plans and throttling): per API key or client.

  • In the application: per user, per tenant and per expensive operation, such as AI generations per day. This is the one that protects your bill.

What to key on

IP addresses are shared (offices, mobile carriers) and cheap to rotate, so IP limits should be generous and aimed at floods. Authenticated limits per user or tenant are the precise ones. Expensive actions need their own limits regardless of request rate: ten requests a minute can still be a thousand-dollar day if each one runs a long model call.

Answering properly

  • Return 429 Too Many Requests (RFC 6585) with a Retry-After header.

  • Tell clients their remaining quota where it helps; an IETF draft standardizes RateLimit headers for this.

  • Make limits visible in your docs and plans, so customers can design for them.

  • Store counters somewhere shared (Redis or Valkey, DynamoDB), not in each server's memory, or limits multiply with instances.

hoolco Monthly Review

Once a month: what changed in tech that month and what it means for you, from cloud and AI to security and the tools you build with. Every item links to its source. No sales pitch, unsubscribe in one click.

As of October 26, 2026. Provided as is, for general information, and accurate to the best of our knowledge on the date shown. Not legal, compliance, tax, financial or other professional advice. Prices, limits and vendor services change; check current vendor documentation before relying on anything here. Terms of use.