Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 32

Design a card payment processing API

Expert · 50 min · Payments & ledgers

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

Done on paper? Compare with the worked approaches