Skip to content
System Design Explorer
Company architectureadvanced

Stripe System Design

Stripe-scale online payments: safe retries, fraud checks and a ledger

By Ankur NayakReviewed

How an online payments API stays correct at nearly $2 trillion a year: every request can be retried safely with an idempotency key, layered rate limiters protect the fleet, fraud is scored in under 100 ms, and an immutable double-entry ledger proves where every cent went.

Open in Studio· edit a copy
Users
5M+ businesses (2025)
Throughput
5M+ DB queries/s (2024)
Storage
2,000+ DB shards (2024)
Total payment volume
$1.9T
API availability
99.999%
Ledger events
~5B per day
Fraud decision
< 100 ms
Stripe system design architecture diagramComponents: Customer's Browser (Stripe.js), Merchant Backend, API Edge, Payments API (PaymentIntents), Radar (DNN), Card Networks & Banks, DocDB (MongoDB-based), Ledger, Webhooks. Connections: Customer's Browser to Merchant Backend (checkout); Merchant Backend to API Edge (POST /v1/payment_intents); Customer's Browser to API Edge (confirm (client secret)); API Edge to Payments API; Payments API to Radar (score); Payments API to Card Networks & Banks (authorise); Payments API to DocDB (PaymentIntent + idempotent result); Payments API to Ledger (money-movement events); Payments API to Webhooks (payment_intent.succeeded); Webhooks to Merchant Backend.Customer's BrowserStripe.jsMerchant BackendServiceAPI EdgeAPI gatewayPayments APIPaymentIntentsRadarDNNCard Networks & BanksExternal APIDocDBMongoDB-basedLedgerSQL databaseWebhooksWorker

Requirements

Functional

  • Accept cards and other payment methods through one API
  • Let clients retry any request without charging twice
  • Screen every payment for fraud before it completes
  • Notify the merchant's systems when a payment succeeds
  • Account for every movement of money

Non-functional

  • Five nines of API availability
  • Never double-charge, never lose a payment
  • A fraud decision within the checkout's time budget (under 100 ms)
  • Database migrations and upgrades with no downtime

In depth

A payments API that has to be right

Stripe sits between millions of businesses and the world's card networks and banks. Its users experience it as an API: create a payment, confirm it, get told when it succeeds. Underneath, the engineering problem is less about speed than about never being wrong about money: never charging twice, never losing a payment, and being able to prove where every cent went. Businesses on Stripe generated $1.9 trillion in total volume in 2025.

Stripe has written publicly about the pieces that make this work, and they line up into a clear architecture: rate limiters at the edge, idempotency in the API, a payment state machine, fraud scoring, a sharded document database and a double-entry ledger.

Safe retries: idempotency keys

The hardest failure in an API is the one where the server did the work but the client never heard back. Did the charge happen? Stripe's answer, described in its 2017 post on idempotency, is to let the client send a unique Idempotency-Key with every request that changes state. Stripe saves the status code and body of the first request with a given key and replays them for any retry; a retry with different parameters is rejected. Keys can be pruned once they're at least 24 hours old.

That one rule changes how clients behave: they can retry blindly after any timeout, with exponential backoff and random jitter so a burst of failures doesn't turn into a synchronised stampede. See idempotency keys.

Protecting the fleet: four kinds of limiter

Before a request reaches payments code it passes Stripe's limiters. The 2017 post describes four:

  • a request rate limiter (a token bucket per user, in Redis) that allows short bursts
  • a concurrent request limiter for expensive endpoints
  • a fleet usage load shedder that reserves part of the fleet for critical requests, such as creating charges, and returns 503 to the rest when capacity runs short
  • a worker utilisation shedder, the last line of defence, which drops test-mode traffic first and sheds slowly to avoid flapping

One design choice stands out: the limiters fail open. If the limiter code errors or Redis goes down, requests are let through, because a protection mechanism must never become the outage. See rate limiting algorithms.

One state machine for every payment method

Stripe's first API was a single call to charge a US card. As it added payment methods that need customer action (3D Secure) or settle later (bank debits), that model broke down. The 2020 retrospective explains the replacement, introduced in 2018: PaymentIntents and PaymentMethods. A PaymentIntent is a server-side state machine: requires_payment_method → requires_confirmation → requires_action → processing → succeeded. There is deliberately no failed state; a failed attempt returns to requires_payment_method so the customer can try another card.

The merchant's server creates the intent, the browser confirms it with a client secret, and Stripe tells the merchant about success through a webhook (payment_intent.succeeded), which keeps fulfilment off the critical path of collecting money.

Fraud in under 100 milliseconds

Between the click and the confirmation, Radar decides whether the payment is fraudulent. Stripe's 2023 post says it looks at more than 1,000 characteristics, draws on signals from across the whole Stripe network, and decides in under 100 ms. In 2022 the team moved from an ensemble of XGBoost and a neural network to a pure deep neural network, which cut training time by over 85%. It incorrectly blocks about 0.1% of legitimate payments.

DocDB: sharding without downtime

API objects live in DocDB, Stripe's in-house database-as-a-service built on MongoDB. Go proxies parse each query and route it using a chunk metadata service to more than 2,000 shards, each a replica set with automated failover. Stripe reported over 5 million queries per second and 99.999% uptime in 2023.

To rebalance, a Data Movement Platform moves chunks between shards: bulk import, asynchronous replication, a correctness check, then a traffic switch that version-gates the source, replicates the last writes and flips the route in under two seconds. In 2023 it migrated 1.5 petabytes and cut the number of shards by about three quarters. It is a descendant of the playbook from Stripe's 2017 post on online migrations: dual-write, switch reads, switch writes, clean up.

The Ledger: proving the money

Every money movement is also published to Ledger, an immutable, double-entry log that serves as the system of record for Stripe's financial data: about five billion events a day as of 2024. Payments are modelled as balances moving between states, so an intermediate (clearing) account should return to zero when a process finishes. Data-quality checks look for balances that don't clear, events that arrive late, and producer records with no matching Ledger event. Corrections are new entries, made through a two-phase review. See double-entry ledger.

What's not public

Stripe hasn't described how its API tier connects to acquirers and card networks, or how webhook delivery works internally. Those parts of the diagram are shown at the level of "this has to exist" and marked as inferred where they make claims.

What to take into an interview

  • Design for the ambiguous timeout: idempotency keys plus retries with backoff and jitter
  • Make protection fail open, and reserve capacity for the requests that matter most
  • Model payments as a server-side state machine, not a single call
  • Keep an append-only double-entry ledger and check that balances clear
  • Plan for online migrations from day one

Components

Customer's Browser

Stripe.js

Client. Collects payment details and confirms the payment with the PaymentIntent's client secret.

Merchant Backend

Service. The business's own server: creates a PaymentIntent for the order and fulfils it when Stripe reports success.

API Edge

API gateway. Every API request passes rate limiters and load shedders before it reaches the payments code.

Why: Limits per user stop one integration from starving everyone else; shedders keep capacity for the requests that move money.

Building block: Rate Limiting Algorithms

Limiter State

Redis

Cache. Token buckets per user and request counts per traffic class.

Payments API

PaymentIntents

Service. Models each payment as a PaymentIntent that moves through states (requires_payment_method → requires_confirmation → requires_action → processing → succeeded). Every POST accepts an idempotency key; the first result is saved and replayed for retries.

Why: One state machine on the server works for cards and for payment methods that need customer action or settle asynchronously.

Building block: Idempotency Keys

Radar

DNN

ML model. Scores each payment for fraud before it completes, using more than 1,000 characteristics and signals from across the Stripe network.

Card Networks & Banks

inferred

External API. Authorise and settle payments. How Stripe connects to acquirers and networks isn't described in these sources.

DocDB

MongoDB-based

NoSQL database. Stripe's in-house database-as-a-service: thousands of replica-set shards behind a Go proxy fleet, with a platform that moves data between shards without downtime.

Why: Online data for every API object needs to scale horizontally and be re-balanced without maintenance windows.

Building block: Database Sharding, Replication

Database Proxies

Go

Service. Parse each query, check admission and access, route it to shards and combine results.

Chunk Metadata

Coordination. Maps chunks of each collection to the shard that owns them.

Shards

Replica sets

NoSQL database. Each shard is a replica set with a primary and secondaries and automated failover.

Building block: Replication

Data Movement Platform

Worker. Coordinates chunk migrations: register, bulk import, async replication, correctness check, traffic switch, deregister.

Oplog Stream

Kafka → S3

Stream. Oplog events stream to Kafka and are archived to S3.

Ledger

SQL database. Immutable double-entry log of every money movement: the system of record for Stripe's financial data.

Why: If balances are derived from balanced, append-only entries, missing or stuck money shows up as arithmetic, not as a customer complaint.

Building block: Double-Entry Ledger

Producer Systems

Service. Charges, refunds, payouts and other systems publish events for each step.

Immutable Event Log

SQL database. Published transactions can't be deleted or modified.

Building block: Double-Entry Ledger

Account Balances

Service. Fund flows between accounts (states) give every account's balance.

Data Quality Checks

Monitoring. Clearing (balances return to zero), timeliness and completeness (every producer ID has a Ledger event).

Corrections

Service. Fixes go through a two-phase review and commit that shows their effect on data quality.

Webhooks

Worker. Sends events such as payment_intent.succeeded to the merchant's endpoint, outside the critical path of collecting money.

Change Data Capture

Kafka

Stream. Database changes stream to Kafka and are archived to S3.

Archive

S3

Object storage. Long-term copy of the change stream.

Request flows

Pay with a card

  1. The customer clicks Pay on the merchant's checkout page.
  2. The merchant's server creates a PaymentIntent for the order amount, sending an Idempotency-Key.
  3. Rate limiters let the request through; the API starts the intent in requires_payment_method.
  4. The intent and the response saved against the idempotency key are written to DocDB.
  5. The merchant gets the PaymentIntent back and passes its client secret to the browser.
  6. Stripe.js confirms the intent with the client secret and the card details.
  7. Radar scores the payment for fraud in under 100 ms.
  8. The card is authorised through the networks and the issuing bank.
  9. The intent moves to succeeded.
  10. The money movement is recorded as balanced entries in the Ledger.
  11. A payment_intent.succeeded event is queued for the merchant.
  12. The merchant's webhook handler fulfils the order; it isn't on the critical path of taking the money.

Retry after a timeout

  1. The merchant's request to create a PaymentIntent times out; it can't tell whether it was created.
  2. It retries with the same Idempotency-Key and the same parameters.
  3. The request passes the limiters and reaches the API.
  4. The key is already known: the saved status code and body are loaded instead of creating a second intent.
  5. The original response is returned. Had the parameters differed, the API would return an error.

The bank asks for 3D Secure

  1. The browser confirms the payment.
  2. The issuer requires authentication, so the intent moves to requires_action.
  3. Stripe.js shows the bank's challenge and the customer completes it.
  4. With authentication done, the payment is authorised.
  5. The intent succeeds and the merchant is notified by webhook.

Failure scenarios

What if: the rate limiter's Redis fails?

Stripe's limiters are designed to fail open: if the limiter code errors or Redis goes down, requests are let through rather than rejected, so the API keeps serving. Limiters also have kill switches and are dark-launched before enforcing.

User impact: None for payments; abusive traffic is briefly unthrottled.

  • Fail open on limiter errors
  • Feature flags and kill switches per limiter
  • Dark launch new limits and watch what they would block

What if: the API fleet is overloaded?

When the fleet runs short of capacity, load shedders protect the requests that matter: a share of capacity is reserved for critical requests such as creating charges, non-critical ones get HTTP 503, and the worker shedder drops test-mode traffic first, shedding slowly to avoid flapping.

User impact: Some dashboards and non-critical calls fail; live payments keep working.

  • Reserve capacity for critical traffic
  • Shed test-mode traffic first
  • Clients retry with backoff, jitter and idempotency keys

What if: a card network or bank is slow?

Authorisation calls time out or return late. The merchant can't tell whether the payment went through, so it retries with the same idempotency key and receives whatever result the first attempt produced instead of charging twice.

User impact: Slow or failed checkouts at the affected bank, but no double charges.

  • Idempotency keys on every POST
  • Exponential backoff with jitter
  • Asynchronous completion through webhooks

Trade-offs

Server-side idempotency for every write

Accept an Idempotency-Key on every POST and replay the first result for retries.

Pros
  • Clients can retry blindly after any network failure
  • No double charges
Cons
  • A lookup and a stored response on every write
  • Keys need expiry (prunable after 24 hours)

Fail-open rate limiting

If the limiter itself breaks, let traffic through.

Pros
  • A limiter bug can't take payments down
Cons
  • During a limiter outage, abusive traffic isn't throttled

A state machine instead of a charge call

Model payments as PaymentIntents that move through explicit states.

Pros
  • One integration for cards, 3D Secure and asynchronous methods
  • Recovers cleanly from customer actions and retries
Cons
  • More concepts for developers than a single 'charge' call

Alternatives: Charges + Tokens (Stripe's original API); Sources (a client-side state machine, 2015–2017)

An immutable double-entry ledger

Record every money movement as balanced, append-only entries and verify balances continuously.

Pros
  • Correctness can be checked by arithmetic
  • Full audit trail
Cons
  • Billions of events a day to store and check
  • Corrections need their own reviewed process

Frequently asked questions

How does Stripe avoid charging a customer twice?

Every POST request can carry an idempotency key chosen by the client. Stripe saves the status code and body of the first request made with that key, so a retry with the same key and parameters gets the saved response instead of creating a second charge.

What is a PaymentIntent?

Stripe's object for one payment, introduced in 2018. It moves through states such as requires_payment_method, requires_action and succeeded, which lets one integration handle cards, 3D Secure authentication and payment methods that complete asynchronously.

How does Stripe detect fraud so quickly?

Radar scores each payment with a deep neural network that looks at more than 1,000 characteristics, including signals from across the Stripe network, and decides in under 100 milliseconds, before the transaction is confirmed.

What database does Stripe use?

Online data lives in DocDB, Stripe's in-house database-as-a-service built on MongoDB. Go proxies route queries to more than 2,000 shards, and a data movement platform migrates data between shards with a traffic switch that takes under two seconds.

Building blocks used

Sources