Business processes / 3 / 12
Double-entry ledger
A marketplace keeps buyer wallets, pays sellers and takes a fee. A balance column updated in place loses money in races and cannot say where it went. A double-entry ledger records every movement as an entry whose postings sum to zero, derives balances from it and never rewrites history.
- 14 min
- Intermediate
- 11 steps
- Unexplained money
- 0 $
- Lost updates
- 0 /day
- Double charges
- 0 /day
- Balance read
- 2 ms
- request
- reply
- redelivery
- duplicate
- lost
Numbers are a model scenario, not measurements
The real request
Wallet API → Wallets tableRequest
SELECT balance_minor FROM wallets WHERE user_id = 'u_42';1
-- 12000: the API subtracts the 4500 order in code
UPDATE wallets
SET balance_minor = 75002
WHERE user_id = 'u_42';
Response
UPDATE 13
balance_minor— Integer cents:12000= $120.00. Never floats for money.SET— The old value is overwritten. Whatever it was is gone.UPDATE 1— The database is happy. It has no idea whether 7500 is right.
Build it yourselfCheat sheetCompare lessons
Course: 74 lessons
01 Foundations
02 Scaling
03 Data & storage
04 Communication
05 Reliability
06 Architecture
07 Security
08 Shipping
09 Whole systems
10 Business processes
11 Case studies