Skip to main content

Real architecture · Mid

Stripe: scaling the API with rate limiters

Real production architecture. Key points: rate limiting algorithms and overload control.

15 min read · Source: Stripe · Content reviewed on October 23, 2026

Short answer

Real production architecture. Key points: rate limiting algorithms and overload control. The first few times traffic spikes suddenly, it is reasonable to just add infrastructure capacity. In a production API, however, you also have to ensure that a bad actor does not affect the disponibilidade for everyone else, on purpose or by accident.

01 · CONTEXT

Why limit a production API

The first few times traffic spikes suddenly, it is reasonable to just add infrastructure capacity. In a production API, however, you also have to ensure that a bad actor does not affect the disponibilidade for everyone else, on purpose or by accident.

According to Stripe, limiting traffic helps in scenarios like these: one user causes a spike and the others must keep being served; one user sends many low-priority requests that cannot get in the way of high-priority ones; something fails internally and low-priority requests must be dropped.

Stripe distinguishes two mechanisms. A rate limiter is appropriate when users can change the pace of their calls without changing the outcome. Load shedding, in turn, drops low-priority requests during incidents so critical ones get through, and decides based on the state of the whole system, not on who made the request.

CriterionRate limiterLoad shedder
When it actsIn day-to-day operationDuring incidents
When it is appropriateWhen users can change their pace without affecting the outcomeWhen low priority must be dropped so critical requests can get through
Basis of the decisionEach user's paceThe state of the whole system

02 · THE FOUR LIMITERS

Limiters and load shedders working together

Stripe operates four kinds of limiters in production. The request rate limiter is by far the most important and the recommended starting point.

The request rate limiter restricts each user to a maximum number of requests per second. Stripe allows briefly exceeding the cap for sudden spikes during real-time events, and keeps the same limiting behavior in test and production modes.

The concurrency limiter is about how many requests can be in flight at the same time, rather than how many per second. Some endpoints consume far more resources, and users frustrated by the wait try again, adding demand to an already overloaded resource. Before adopting it, Stripe frequently dealt with contention on the most expensive endpoints; according to the post, it solved the problem completely.

The fleet usage load shedder separates traffic into critical methods, such as creating charges, and non-critical ones, such as listing charges. A Redis cluster counts the requests of each type, and a fraction of the infrastructure is always reserved for the critical ones, so non-critical requests above their share are rejected.

The worker utilization load shedder is the last line of defense. If a machine is too busy, it starts dropping less critical requests, beginning with test traffic, and escalates to more traffic if that is not enough. Dropping and restoring traffic must be slow, otherwise the system oscillates between the two states. According to the post, it limits the impact of incidents that are already happening, while the first three are preventive.

CriterionRequests per secondConcurrencyFleet usageWorker utilization
What it controlsEach user's requests per secondRequests in flight at the same timeFraction of the fleet reserved for critical requestsWorkers with free capacity
Trigger frequencyConstantementeMuch less than the rate limiterA very small fraction of requestsVery rarely, only in major incidents
PapelPrevent abuseControl CPU-intensive endpointsGuarantee part of the fleet for what matters mostDamage control during ongoing incidents
  1. The client's request reaches the limiter layer, which decides whether it goes ahead.

    Architecture diagram: API with limiting layers
    CLAPI client
    NWLimiter layerdecide
    CHLimiters' Redis
    CPAPI workers
    NWMetrics and alerts
  2. The layer checks the user's token bucket in Redis and takes one token for each request.

    Architecture diagram: API with limiting layers
    CLAPI client
    NWLimiter layer
    CHLimiters' Redisuser bucket
    CPAPI workers
    NWMetrics and alerts
  3. With an empty bucket, the request is rejected: this is the rate limiter acting on that user.

    Architecture diagram: API with limiting layers
    CLAPI client
    NWLimiter layerrejeita
    CHLimiters' Redis
    CPAPI workers
    NWMetrics and alerts
  4. A Redis cluster also counts the requests of each type; non-critical ones above their allotted share are rejected so capacity is left for the critical ones.

    Architecture diagram: API with limiting layers
    CLAPI client
    NWLimiter layer
    CHLimiters' Rediscount per type
    CPAPI workers
    NWMetrics and alerts
  5. On the workers, if the queue tightens, the last line of defense starts dropping less critical traffic, beginning with test mode.

    Architecture diagram: API with limiting layers
    CLAPI client
    NWLimiter layer
    CHLimiters' Redis
    CPAPI workersdrops traffic
    NWMetrics and alerts

03 · IMPLEMENTATION

Token bucket in Redis

Stripe uses the token bucket algorithm, with a central bucket host: each request takes a token, and new tokens drip into the bucket gradually. With an empty bucket, the request is rejected. Each user has their own bucket, and the implementation uses Redis, which can be self-operated or, on AWS, be a managed service such as ElastiCache.

When rejecting, you must choose between HTTP 429 and HTTP 503 depending on the situation, and the message returned should be actionable for the caller.

04 · SAFE ROLLOUT

Introducing limiters without breaking users

A new limiter can block people who should not be blocked. Stripe recommends kill switches to turn it off if it acts by mistake, with feature flags as a human escape hatch, plus alerts and metrics to know how often it triggers.

It also recommends a dark launch of each limiter, to observe the traffic it would block. The idea is to find thresholds that keep the API up without affecting users' existing request patterns, which may involve working with some of them to change their code.

  1. On the normal path, the middleware queries Redis before deciding the request's destination.

    Architecture diagram: Limiting that fails open
    CLAPI client
    NWLimiting middleware
    CHLimiters' Redisbucket checked
    CPAPI service
    NWMetrics and alerts
  2. Imagine the limiters' Redis goes down or there is a bug in the limiting code.

    Architecture diagram: Limiting that fails open
    CLAPI client
    NWLimiting middleware
    CHLimiters' Redisunavailable (scenario)
    CPAPI service
    NWMetrics and alerts
  3. The middleware catches the exception and fails open: the request proceeds to the service and the API stays functional.

    Architecture diagram: Limiting that fails open
    CLAPI client
    NWLimiting middlewarefails open
    CHLimiters' Redis
    CPAPI servicekeeps serving
    NWMetrics and alerts
  4. In case the limiters act by mistake, feature-flag kill switches turn them off, and alerts and metrics show how often they trigger.

    Architecture diagram: Limiting that fails open
    CLAPI client
    NWLimiting middlewareswitchable by flag
    CHLimiters' Redis
    CPAPI service
    NWMetrics and alertstrigger frequency

05 · LESSONS

Where to start

According to the post, not all of the strategies are needed on day one. Start with the request rate limiter and introduce the other three over time, to prevent different classes of problems, as the need arises.

Frequently asked questions

What is Stripe: scaling the API with rate limiters?

Real production architecture. Key points: rate limiting algorithms and overload control.

What does the Stripe: scaling the API with rate limiters design cover?

It is organized in these sections: Why limit a production API, Limiters and load shedders working together, Token bucket in Redis, Introducing limiters without breaking users, and Where to start.

How long is Stripe: scaling the API with rate limiters and what level is it?

It takes about 15 minutes to read and is rated Mid level.

Now design it yourself

Run this case as an interview in the System Design school: you make the decisions, the tutor challenges them and you see how your design scores.