SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 32
Design a card payment processing API
You run a payment service that online shops integrate with. At checkout the shop collects card details through your form, asks you to authorize an amount with the customer's bank via the card networks, and later captures the money, refunds it, or lets the authorization lapse. Shops learn outcomes from API responses and from webhooks.
Requirements
- Collect card details on the checkout page and return a token, so merchant servers never see raw card numbers.
- Authorize an amount; capture it fully or partially within 7 days, void it, or refund a captured payment partially or fully, never refunding more than was captured.
- Make every state-changing API call safe to retry with a merchant-supplied idempotency key.
- Notify merchants of payment state changes through signed webhooks that are retried until acknowledged.
- Reconcile the acquiring bank's daily settlement files against your records before paying merchants out.
Constraints and assumptions
- 2,000 authorizations per second on average, 10,000 per second at peak sales events.
- Card network and issuer responses take 300 ms to 3 s; you time out at 10 s, and occasionally no response ever arrives.
- Authorize API p99 under 4 seconds including the network round trip.
- Raw card data must stay inside a small, separately audited zone; everything else should be out of compliance scope.
- Amounts are integers in minor units across 30 currencies; each acquirer sends one settlement file per day with up to 50 million lines.
Out of scope for the first sketch
Fraud scoring internals (assume a risk check answers allow or deny in 50 ms) · Chargebacks and disputes · Customer authentication challenges such as 3-D Secure · Currency conversion · Merchant onboarding
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design a card payment processing API
Finish your first sketch before answering these. Cross out freely.
- The merchant's server times out and retries an authorize with the same idempotency key while the first call is still waiting on the network. What happens?
- The card network never answers an authorization. Was the customer charged, and what do you do about it?
- Which components ever see a raw card number, and how do you keep everything else out of that scope?
- A merchant's webhook endpoint is down for 6 hours. How are events delivered afterwards, in what order, and how does the merchant catch up?
- The settlement file shows a $10.00 capture for a payment your database says was voided. How do you find mismatches like this and resolve them?
Compare afterwards: worked approaches and reading at sketchbook /questions/card-payments/review