11. Classic design problemsPayments
Payments
A payments system moves money between customers, merchants and the company, usually by calling an outside processor like Stripe or a card network, and its first rule is that money must never be created, lost or double-charged. Internally it keeps a double-entry ledger: every movement is recorded as matching debit and credit entries that sum to zero, so the books always balance and every cent can be traced. The interesting problem is uncertainty: if the processor times out, you don’t know whether the charge happened, so you record the payment as pending, retry with an idempotency key so it can’t be charged twice, and regularly reconcile your ledger against the processor’s records to catch anything that drifted.
In this lesson: A double-entry ledger plus a reconciliation diff.