Rate Limiters and Load Shedding
Four Limiters, One Name
The naive mental model of rate limiting is "count requests, reject the excess." That model has exactly one failure mode in mind — too many requests per second — and misses three other ways a fleet degrades under load. Stripe's post enumerates four separate limiters, each measuring something different and each shedding a different kind of traffic:
| Limiter | Protects against | Measures | Sheds | Cannot prevent |
|---|---|---|---|---|
| Request rate limiter | A single user sending too many requests per second | Requests/sec per user, via a token bucket | Requests over the per-second cap → 429 | A handful of slow requests that never exceed the per-second rate but hold workers open (below) |
| Concurrent requests limiter | A user's in-flight requests exhausting the worker pool | Requests currently open per user | New requests once the user's concurrency cap is hit → 429 | Many users each staying just under their own concurrency cap, collectively saturating the fleet (below) |
| Fleet usage load shedder | Non-critical traffic starving critical traffic (e.g. listing charges crowding out creating charges) when the fleet is contended | Share of total fleet capacity currently consumed by non-critical request types | Non-critical requests once they exceed their reserved allocation → 503 | A single misbehaving user operating entirely within critical, per-user limits |
| Worker utilization load shedder | Fleet-wide cascading failure during a major incident | Worker queue depth / utilization, fleet-wide | Traffic progressively by class as utilization climbs → 503 | The incident that spiked utilization in the first place — this only buys time, it doesn't fix the cause |
- Request rate limiter checks the bucket first. Cheapest check, runs before any real work is done — reject fast on an empty bucket rather than let the request reach a worker at all.
- Concurrency limiter checks in-flight count. A request that passed the rate check still has to clear this — it protects against the slow-request case the rate limiter structurally cannot see.
- Fleet usage shedder checks the traffic-class mix. Only relevant once the fleet is contended; a quiet fleet never invokes this layer's rejection path.
- Worker utilization shedder is the last resort. Fleet-wide, class-based, deliberately slow to react in both directions — this is damage control during an incident, not routine admission control.
1. Request Rate Limiter — Token Bucket
Every account gets a bucket with a fixed capacity (the burst allowance) that refills at a fixed rate (the steady-state limit). Each request removes one token; a request that arrives with an empty bucket is rejected. Stripe's post states this plainly: "We use the token bucket algorithm to do rate limiting… every Stripe user has a bucket, and every time they make a request we remove a token from that bucket," implemented in Redis so every API host shares one authoritative counter per account instead of each host tracking its own local, inconsistent view.
tokens(t) = min( capacity, tokens(t−Δt) + refill_rate × Δt )
request admitted ⇔ tokens(t) ≥ 1, then tokens(t) −= 1
The token bucket is not the only way to rate-limit, and the alternatives fail in specific, memorable ways:
| Approach | How it works | Failure mode |
|---|---|---|
| Fixed window | Count requests in the current second; reset the counter every second boundary | Boundary burst: a user can send the full quota at 0.99s and the full quota again at 1.01s — 2× the intended rate in a 20ms window, because the counter resets don't know about the traffic that just happened in the previous window |
| Sliding window log | Store every request's timestamp; count how many fall in the trailing window | Perfectly accurate, but memory cost scales with request volume — storing a timestamp per request per user is expensive at Stripe's request volume and gets worse the higher the limit |
| Token bucket | One counter (or two: tokens + last-refill-timestamp) per user, refilled lazily on each request | Permits legitimate bursts up to capacity without the boundary-burst bug, and costs O(1) storage per user regardless of request volume — this is why it's the standard choice for a per-user API limiter |
The burst allowance matters operationally: Stripe explicitly designs for "real-time events" like flash sales, where a legitimate integration needs to fire a cluster of requests faster than its steady-state rate for a few seconds. A fixed window either has to set the window quota high enough to allow that burst — which means it also allows a 2× boundary burst as noise — or reject legitimate traffic. A token bucket decouples "how much can I burst" (capacity) from "what's my steady rate" (refill rate), so you can tune them independently.
2. Concurrent Requests Limiter
This is the limiter the naive mental model misses entirely, and Stripe's post calls it out as solving a real, distinct incident: users making too many requests at one time on CPU- or I/O-heavy endpoints. The request rate limiter counts requests arriving; it has no idea how long a request takes to finish. A handful of pathologically slow requests can hold a disproportionate share of the worker pool without ever tripping a per-second cap:
concurrent_in_flight ≈ arrival_rate (req/s) × mean_request_duration (s)
Worked example: a client sends a steady 10 requests/second — comfortably under almost any per-second rate limit — but each request is a list call with heavy expansions that takes 30 seconds to complete instead of the usual tens of milliseconds. 10 × 30 = 300 requests in flight simultaneously, all from one account, none of which the rate limiter ever objected to. If the fleet allocates, say, 50 workers per host across a few hosts, that single client can starve every other tenant on those hosts even though it never exceeded its per-second budget once.
This maps directly onto the current docs' separate concurrency limits, which "restrict the number of simultaneously active requests, separate from rate limits," and explicitly call out that "list requests… and those that include expansions generally use more resources and take longer to run" — the exact shape of the worked example above. The docs also note a related but distinct 429 lock_timeout error: an object-level lock (not a rate limit) that fires when concurrent requests contend for the same object, with the fix being to serialize writes to that object rather than back off the whole client.
3. Fleet Usage Load Shedder
This limiter operates at the fleet level, not the per-user level, and answers a different question: when the fleet as a whole is under load, which kinds of requests get to keep running? Stripe reserves a fraction of total capacity for critical traffic — creating a charge — and lets non-critical traffic — listing charges — fill the rest, up to its own allocation: "If our reservation number is 20%, then any non-critical request over their 80% allocation would be rejected" with a 503.
The distinction between per-user limiters (1 and 2) and this one matters: a single well-behaved user, individually under every per-user cap, can still be shed here — because the shedder isn't tracking them, it's tracking the aggregate mix of critical vs. non-critical requests across the whole fleet in real time via a Redis-backed counter. It is the mechanism that keeps "can I create a PaymentIntent" working even while "can I page through six months of Balance Transactions" is degraded.
4. Worker Utilization Load Shedder
The last line of defense operates purely on fleet-wide worker utilization, independent of what any individual request or endpoint is doing. As utilization climbs, it sheds progressively by traffic class — Stripe's post describes four tiers: critical methods first protected, then POSTs, then GETs, then test-mode traffic shed earliest. It triggers rarely — the post reports only about 100 requests shed by this layer in the measured month, versus millions by the request rate limiter — because it only activates during genuine incidents, and Stripe deliberately makes shedding and recovery slow ("shedding and bringing load happen slowly") to avoid flapping: a shedder that reacts instantly to a utilization spike and instantly un-sheds when it dips will oscillate, turning one incident into a rhythmic outage.
Per-User, Not Global — the Same Isolation Principle as Idempotency: the contract
All four limiters key on the account, not on the API as a whole, for the same reason idempotency keys are scoped per API key rather than globally unique across Stripe (see Idempotency: the contract): a shared namespace lets one tenant's mistake degrade every other tenant. A global request-rate counter would let one runaway integration exhaust the entire budget and rate-limit every other Stripe user simultaneously; a global idempotency key namespace would let one account's key collide with — or be guessed and replayed against — another account's request. Both design choices are instances of one rule: the isolation boundary is the tenant, not the system, applied once at the write path (idempotency) and once at the admission path (rate limiting).
| Global API rate limit — live mode | 100 req/s per account |
|---|---|
| Global API rate limit — sandbox | 25 req/s per account |
| Most individual endpoints | 25 req/s |
| PaymentIntents | 1000 update requests / PI / hour |
| Payouts | 15 creates/s, 30 concurrent per business |
| Read (GET) allocation | avg 500 reads/transaction, min 10,000/mo |
| Myth | Reality (current docs) |
|---|---|
| "Rate limiting behaves identically in test and live mode" — true per the 2017 post, which states the API "provides the same rate limiting behavior in both test and live modes" | The current docs specify different numbers: 100 req/s in live mode vs. 25 req/s in sandbox for the global limit, and sandbox is explicitly lower everywhere. Load-testing against a sandbox is discouraged for exactly this reason — you'll hit limits there that production wouldn't hit, and sandbox latency doesn't resemble live-mode latency either, since live mode actually round-trips to a card network and sandbox mocks it. |
| "Write requests are rate-limited more gently than reads, since writes are rarer" | The opposite framing applies to allocations: write API requests have no allocation limit in the current docs, while read (GET) requests are capped by a transaction-proportional allowance (avg. 500 reads per transaction, 10,000/month minimum). Reads, not writes, are the budget-constrained resource — because unbounded polling loops are a more common integration bug than unbounded write traffic. |
Response Codes and the Client's Obligation
A rate- or concurrency-limited request returns 429 Too Many Requests with a Stripe-Rate-Limited-Reason header naming which layer rejected it:
| Header value | Meaning |
|---|---|
global-rate | Exceeded the account-wide rate limit |
endpoint-rate | Exceeded the rate limit for this specific endpoint |
global-concurrency | Exceeded the account-wide concurrency limit |
endpoint-concurrency | Exceeded the concurrency limit for this specific endpoint |
resource-specific | Exceeded a limit scoped to a resource family (e.g. Subscriptions' update endpoints collectively) |
A 429 without that header is a different error: lock_timeout, from object-level locking, not admission control (above) — the docs are explicit that it "doesn't process these failed requests," so it never gets a request ID, and the fix is serializing writes to that object, not backing off the whole integration. Fleet- and worker-level shedding return 503 instead of 429, signaling "the server is overloaded" rather than "you personally are over budget" — a distinction worth preserving in your own client's error handling, because the correct response differs (see below).
Stripe's guidance for handling 429: retry on an exponential backoff schedule, and "add randomness to the backoff schedule to avoid a thundering herd effect." The arithmetic behind that warning is concrete, not superstitious. Suppose 500 clients are all rate-limited in the same one-second window against a 100 req/s global cap. Without jitter, every client waits the same fixed interval and retries at the same instant:
Every retry cycle re-creates the exact condition that caused the first rejection, because every client's clock and backoff schedule move in lockstep. Adding randomness — a uniform jitter added to each client's wait, e.g. backoff × (1 + random(0, 1)) — spreads the 500 retries across a window instead of a single instant, so most of them succeed and only the unlucky tail collides again. This is also why Stripe's own docs additionally recommend a client-side token bucket to self-throttle proactively, rather than relying solely on reactive backoff after a rejection.
✗ No jitter, fresh key on retry
def charge(order):
key = new_idempotency_key() # regenerated every call — wrong
resp = stripe.PaymentIntent.create(
idempotency_key=key, ...)
if resp.status == 429:
sleep(1) # every client sleeps the same 1s
return charge(order) # loops back in with a NEW key✓ Jittered backoff, stable key
def charge(order):
key = derive_key(order.id) # same key every attempt for this order
for attempt in range(MAX_TRIES):
resp = stripe.PaymentIntent.create(
idempotency_key=key, ...)
if resp.status != 429:
return resp
wait = backoff(attempt) * (1 + random()) # jitter
sleep(wait)
raise RetriesExhausted(order.id)A retry after a
429is exactly the retry idempotency keys exist to make safe (see Idempotency: the contract, Idempotency: the machinery) — a backoff-and-retry policy with no idempotency key is not resilience, it's a double-charge generator with a delay timer.
Degradation in Layers — and the Two Patterns People Reach for Instead
The general principle underneath all four limiters: a system under overload should fail progressively — shed the least-important traffic first, then the next tier, then the next — rather than falling over uniformly the moment any limit is crossed. That principle is easy to conflate with two other well-known resilience patterns that solve adjacent but different problems:
| Pattern | Protects | Mechanism | Typical mistake |
|---|---|---|---|
| Rate limiter / load shedder | The callee (server), from being overwhelmed by callers | Admission control: reject or shed requests before they consume server resources | Applying it only at the edge, so an internal fan-out still overloads a downstream dependency that has no limiter of its own |
| Circuit breaker | The caller, from piling up threads/connections waiting on a slow or failing dependency | Trip open after a failure/latency threshold; fail fast instead of waiting; half-open probes to detect recovery | Using it as a substitute for a timeout — a breaker with no per-call timeout still lets one slow call hang a thread before the breaker has enough failed calls to trip |
| Bulkhead | Other failure domains, from one saturated dependency starving everything else | Separate resource pools (thread pools, connection pools) per dependency, so exhausting one can't exhaust another | Sizing every bulkhead identically regardless of call volume or criticality — defeats the point, which is deliberately uneven allocation (exactly what the fleet usage shedder's 80/20 split does) |
Stripe's rate limiter and load shedders are all instances of the first row — they protect Stripe's fleet from its callers. A circuit breaker belongs in your code, wrapping calls to Stripe (or to your own downstream services): it's what keeps a Stripe outage from cascading into your API also timing out for every one of your customers, not just the ones making payments.
The fix is not "remove the internal rate limiter" — it's making the webhook handler return 2xx immediately after durably recording the event (the Webhooks part's consumer-side idempotency ledger) and doing the throttled downstream work asynchronously, off the request path Stripe is timing.
The Invariants
- Guarantees: Each of the four limiters bounds exactly the resource it measures — request rate, concurrent requests, fleet-wide non-critical share, or fleet-wide worker utilization — per account, independently of the others. A
429or503is always attributable to one specific layer (viaStripe-Rate-Limited-Reasonfor the first two, absence of that header plus a503for the latter two). - Does not guarantee: That staying under one limiter protects you from another — a slow-but-infrequent request pattern can still exhaust concurrency; a well-behaved single account can still be shed by the fleet-wide layers during someone else's incident. It also does not make retries safe by itself: rate limiting tells you when to retry, not whether a bare retry is safe to send — that's the idempotency key's job (see Idempotency: the contract, Idempotency: the machinery), not the rate limiter's.