Lesson 1 of 9 · 23m
Rate Limits Are Resource Governance, Not Request Counting
Price expensive operations by the capacity they consume and the abuse they enable, not merely by how many HTTP requests arrived.
The worst rate limiter I ever inherited was mathematically impeccable. It counted requests exactly, enforced 600 per minute exactly, and let one customer bankrupt the SMS budget with twelve requests. Each request fanned out to thousands of messages. The limiter was correct and the system was wrong. Rate limiting is resource governance: you are pricing cost, risk, and fairness, not counting packets for sport.
Start with the resource inventory
Before choosing an algorithm, list what each endpoint consumes:
login attempt password-guessing budget
password reset email/SMS spend and user harassment
search database rows scanned and cache pressure
export worker minutes, memory, queue occupancy
file upload disk, bandwidth, malware-scan CPU
webhook delivery outbound connections and partner goodwill
object creation inventory exhaustion and downstream workflowsThe correct unit is often not request. It may be message, row scanned, byte, job, target identity, tenant, or dollar. A mature design prices the dangerous unit directly.
Separate four questions people merge into one
Teams say "rate limit" when they mean four different controls:
rate requests or events per unit of time
burst how much work can arrive at once
quota cumulative allowance over a longer period
concurrency how many expensive units may run simultaneouslyAn export API can allow 10 requests per minute, 2 concurrent exports, 20 exports per day, and a maximum of 5 queued jobs. Those controls solve different problems. Conflating them produces systems that either fall over under parallelism or punish ordinary interactive use.
Every limit needs an abuse story
Write the threat in concrete language:
A credential stuffer rotates IPs while targeting one account.
A trial tenant queues exports until workers starve paid tenants.
A buggy integration retries writes and duplicates orders.
A scraper uses cheap sessions to crawl expensive search.That story determines the key, window, cost weight, and response. Without it, engineers pick defaults like "100 per minute per IP" because that is what a framework demo showed.
Count cost before the side effect
A rejection that happens after sending SMS, enqueueing work, or charging a card is not protection. Reserve or check budget before the expensive action, then settle actual cost afterward:
authorize cost -> perform work -> record actual cost -> release reservationFor idempotent operations, make the idempotency key part of the accounting story. Otherwise retries either multiply spend or consume quota for work the client never received.
Field notes
- 429 means "this decision path refused work"; it does not prove the expensive side effect was prevented.
- Averages hide abuse. Ten requests per second sustained is different from 600 in one second.
- Legitimate automation is often spiky because jobs start on minute boundaries.
- If the business cannot state what is being protected, the limiter will protect the wrong thing.
Was this lesson helpful?