SD-32 · Back to the write-up
Design a Card Payment Processing
Save each payment step behind an idempotency key, authorize through a token in a card-data zone, reverse every unknown, and book every cent twice.
Follow a request
Enter a card
Authorize a payment
Bank times out
Notify the merchant
Capture and settle
Merchant
Edge
Payment services
Card zone, data and networks
Checkout scriptShopper's browser
Merchant serverRetries with a key
API gatewayKeys + idempotency
Payment APIState machine
Risk scoring50 ms budget
Payments DB16 shards
Card vaultTokens, HSM keys
Network adapter16 acquirer links
Card networksAcquirers + banks
LedgerDouble entry
SettlementNightly + recon
Webhook workersFrom the outbox
Idempotency-Key: ord-881-a1.1 / 11The numbers, at a glance
8 msGateway + idem
12 msFraud
15 msDB writes
10 msVault + adapter
280 msNetwork + bank
≈ 4% vault + adapter96% handle only tokens
1 retry: must return the saved answer99 first tries
An authorization, in order
Happy path. On a timeout, the adapter sends a reversal before step 9 and the result is declined.
Merchant
Gateway
Payment API
Payments DB
Adapter
Vault
Network
1 POST /payments + Idem-Key
2 new key, payment id
3 created + key, then authorizing
4 authorize(token)
5 detokenize
6 card number
7 0100 auth, trace no
8 0110 approved
9 approved, auth code
10 authorized + outbox
11 201 authorized
12 201 authorized
RequestResponseAsync, does not block
When the bank does not answer
The decision this question is really about.
auth → timeout
auth again
charged twice
+ Usually works on the second try.− Two holds if the first was approved.
auth → timeout
status = failed
charged, nothing shipped
+ Fast, clear answer.− The bank may have approved it.
save authorizing
auth → timeout
reversal until acked
declined, same answer on retry
+ Every outcome is known; retries are safe.− More states and a recovery job.
How it grows
Add a box only when a number forces you to. Highlighted boxes are new at each stage.
Merchant
App server
DatabaseCard network
Checkout scriptMerchant
Gateway
Payment API × 2
Payments DBLedgerVault + adapter
Checkout scriptMerchant
Gateway
Payment API × 4Risk scoring
Payments DB × 16Ledger16 acquirer links
Webhook workers
Checkout scriptMerchant
Gateway
Payment API × 8Risk scoring
Payments DB × 16Ledger + sub-accounts16 acquirer links
Webhook workersSettlement + recon
Was this walkthrough useful?Your vote tells us what to improve next.