Low throughput, zero tolerance. Here the hard part is not scale but correctness across unreliable networks: never charge twice, never lose money, and prove it with a ledger.
Requirements. Charge customers through a payment service provider (PSP) such as Stripe or Adyen, pay sellers out, refund, and reconcile with the PSP; correctness comes first: no double charges, no lost payments, an auditable history of every movement of money, and card data never stored by us.
Payments
12 per second1M a day
Peak
120 per secondBlack Friday, 10×
Verdict
one databasespend the effort on correctness
The design. Checkout sends a payment request with an idempotency key, such as the order ID, and the payment service records the order before calling the PSP, which holds the card data. A timeout means the outcome is unknown, so the service retries with the same key or asks the PSP for the status, and the PSP charges at most once. On success the wallet and a double entry ledger are written in one transaction, or through the outbox pattern. Every night, reconciliation matches the PSP’s settlement file against the ledger line by line.
Interview prompt
Design the payment backend for a marketplace: customers pay, sellers get paid out, and the books always balance.
Requirements and estimates
Functional requirements
Pay-in: charge the customer through a payment service provider (PSP) such as Stripe or Adyen.
Pay-out to sellers, refunds.
Reconciliation with the PSP.
Non-functional requirements
Correctness first: no double charges, no lost payments.
Auditable history of every movement of money.
Card data never stored by us (PCI DSS scope).
Estimates
Payments 1M per day ÷ 86,400 s ≈ 12 per secondPeak Black Friday, 10× ≈ 120 per secondVerdict one database handles this; spend the design effort on correctness
The flow
Money moves in the PSP; we move records. The payment service records the order before calling out, the PSP confirms by webhook, and only then do the wallet and ledger change. Reconciliation compares the PSP’s settlement file with the ledger every night.
Step by step
Checkout sends a payment request with an idempotency key, for example the order ID. The payment service stores the order as NOT_STARTED.
The executor calls the PSP. Card details never touch our servers: the PSP’s hosted page or SDK turns them into a token.
The PSP answers, or calls our webhook later, and the order moves to SUCCESS or FAILED.
On success, the wallet balance and ledger entries are written in one transaction, or through the outbox pattern if they live in different services.
Nightly, reconciliation matches the PSP settlement file line by line against the ledger and flags every mismatch.
Simulator: a timeout, a retry, and the idempotency key
Charges at the PSP
Charges
0
Buyer charged
€0
Idempotency table
Key
Stored result
Empty
A timeout does not mean the charge failed. The server may have finished the work and only the response was lost. Retrying is necessary (at least once), and the idempotency key makes the retry harmless (at most once). Together they give the exactly once effect.
Whiteboard
What you sketch in the first five minutes: the retry that must not charge twice, then the ledger that proves it.
1. A timeout is not a failure
Say: the charge may have happened; only the answer was lost.
Charge €50 with the idempotency key ord_7f3a; the response times out.
Retry with the same key: the PSP finds the key and returns the first result.
The buyer is charged €50, once.
Next question: the PSP is down. Route to a second PSP behind a circuit breaker, or fail fast and let the buyer try again.
2. Every euro written twice
Say: debits and credits always balance, so a broken book points at its transaction.
A €50 payment debits the buyer’s card, via the PSP, €50.00.
It credits the seller payable €45.00 and the platform fee €5.00.
A refund is a new pair of entries, never an edit.
Next question: reconciliation finds a mismatch. Known patterns, such as a late webhook, are fixed automatically; the rest go to finance for review.
The double entry ledger
Entry
Account
Debit
Credit
1
Buyer, card via PSP
€50.00
2
Seller payable
€45.00
3
Platform fee revenue
€5.00
Total
€50.00
€50.00
Every transaction debits and credits the same total, so the sum of all entries is always zero. Entries are append only: a refund is a new pair of entries, never an edit. If the books ever fail to balance, you can trace exactly which transaction broke them.
Retries and distributed steps
Retry with exponential backoff and jitter: about 1, 2, 4, 8 seconds, each randomized so thousands of clients do not retry in lockstep. Then stop and alert.
Check before retrying an unknown outcome: query the PSP for the payment’s status using the same key.
Outbox pattern: write the state change and the event to publish in the same database transaction; a relay publishes the event afterwards. No “saved but never announced” gaps.
Saga for multi-step flows: each step has a compensating action (a refund undoes a charge) instead of a distributed lock.
Store money as integers in minor units (cents) with a currency code. Floating point cannot represent 0.10 exactly.
What the interviewer probes next
The PSP is down. What do customers see?
Route to a secondary PSP where contracts allow, protected by a circuit breaker so failing calls stop quickly. If none is available, fail fast with a clear error; never leave a payment in an unknown state without a follow up job to resolve it.
How are sellers paid out?
A daily batch sends pay-outs through the PSP or a bank, with the same idempotency keys and ledger entries. Funds are held for a period so refunds and chargebacks can be covered.
What does reconciliation do with a mismatch?
Classify it. Known patterns (a delayed webhook) are fixed automatically; unknown ones go to a finance queue for manual review. The point is that no discrepancy goes unnoticed for more than a day.
What is a chargeback, and how does the ledger handle it?
The customer disputes the charge with their bank, which pulls the money back. The ledger records reversing entries against the seller’s balance, which may go negative until the next pay-out settles it.