Stripe
Payments with idempotency, strong consistency, and double-entry ledgers
Stripe exposes payments as an API with strong consistency, idempotency keys, and a double-entry ledger per merchant. Every charge is durable and replayable; webhooks notify merchants. Correctness and auditability dominate over raw throughput.
Product constraints
- Money must never be lost or double-counted — strong consistency required.
- Idempotent retries so network failures don't double-charge.
- Full auditability and a ledger per merchant.
- Webhooks to notify merchants of async state changes (refunds, disputes).
High-level diagram
Request path
- Charge. Merchant POSTs a charge with an Idempotency-Key; the API validates and writes to a strongly-consistent ledger.
- Ledger. A double-entry ledger records the movement of money (merchant balance, fees, card network) transactionally.
- Card network. The charge is sent to the card network asynchronously; the result updates the charge state.
- Webhook. On state change (succeeded/failed/refunded), Stripe POSTs a signed webhook to the merchant; retries until 2xx.
Data model
Charges, customers, and balances in a strongly-consistent relational DB. A double-entry ledger records every money movement. Idempotency keys dedupe retries. Events (for webhooks) stored and delivered at-least-once.
Storage / cache / queue choices
Strongly-consistent relational DB (sharded by merchant); double-entry ledger.
Minimal on the write path (correctness > speed); caches for read-heavy lookups.
Internal queues for card-network calls and webhook delivery (at-least-once).
Scaling levers
- Shard by merchant so a merchant's data is co-located and consistent.
- Idempotency keys make retries safe.
- Double-entry ledger gives auditability and correctness.
- Async card-network calls + webhooks decouple slow external systems.
Copy vs skip (for a smaller team)
- Idempotency keys on all mutating endpoints.
- Double-entry ledger for money movement.
- Shard by merchant for co-located consistency.
- Signed, retried webhooks for state changes.
- Eventual consistency for money (use strong/transactional).
- Caching the write path (correctness first).
- Single global ledger (shard by merchant).
Related terms
Idempotency, ACID, Two-phase commit (2PC), Webhooks, Sharding key