~learn.
0:00 / 1:21
Interview problem · Payment system

One line of code moves the money. Nobody can say why it's wrong.

transcript

One line of code. Add 970 to the seller's balance. Easy to write. And when it's wrong, nobody can say why.

A balance column is one number, edited over and over. When it's wrong, there's no trail. Just a wrong number. Payment systems use a double-entry ledger. Every movement sums to zero. Written once. Never edited. Any balance is a sum of entries.

The customer pays 1,000 rupees. Debit PSP receivable. The PSP owes us. Credit the seller's payable, 970. We owe the seller. Credit fee revenue, 30. Debits 1,000. Credits 1,000. Balanced.

Next day the PSP pays out. 980 lands in our bank. It kept a 20 rupee fee. Debit fees expense, 20. Credit the receivable, 1,000. Cleared. Balanced again.

Now a bug double-credits sellers. With a balance column? Silently wrong money. With a ledger, it won't balance against the PSP receivable. Reconciliation flags it before payouts run. And the fix? New entries that reverse the old ones. Never an edit.

Every entry balances. So the whole ledger sums to zero. Never edit money. Write new entries, and keep the trail.

Full breakdown in the lecture.