Continue where you left off ×
The Ledger That Cannot Lie, build a small money ledger in Go and hold it to four promises
The Double-Entry Ledger · Open board
The double-entry ledger as one picture: events in, balanced entries, balances read off. This lesson builds a small one in Go, stage by stage, and then tries to break it.
Education, not financial advice.
Before you start. From Every Litre Leaves One Tank and Enters Another, double-entry, normal balances and the trial balance : a ledger is accounts and entries, every transaction sums to zero, and the trial balance is the alarm. From A Book You Never Erase, the append-only ledger, reversals and derived balances : entries are only added, a mistake is fixed by a reversal, and a balance is derived from the entries. From Half a Point a Day, Gone, integer minor units, rounding and currency exponents : money is whole minor units, never floats. From The Hold That Is Not Money Yet: authorisation, capture, clearing, settlement and chargebacks : a card payment passes through a clearing account before it is cash. You need Go 1.22 or newer to run the code. You can read the lesson without it.
The idea in 30 seconds
A ledger’s promises are four testable sentences: transactions balance, a key is used once, the journal only grows, and balances can be rebuilt from it.
Money is an integer count of minor units, and an input with no whole-unit meaning is refused, not rounded.
An idempotency key belongs to the intention, not the attempt: the same key and body returns the first answer, the same key with a different body is an error.
A mistake is a reversal of the exact negative, allowed once. The old line and the new line both stay.
A reconciliation does not fix a gap. It lists every line it could not match, and the gap equals the sum of the breaks.
Read the story
Lesson 54 of 58 in Finance
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson 16 February 2024: five billion events a day, and a promise The four promises Stages 1 and 2: whole units, and a transaction that must balance Stages 3 and 4: a retry changes nothing, and nothing is edited Stages 5 and 6: two writers, and the bank’s opinion Stage 7 and the test that makes it a promise Ten posting exercises Review Finance
Connects to
Charged Twice (idempotency & exactly-once) System Design Every Litre Leaves One Tank and Enters Another, double-entry, normal balances and the trial balance Finance A Book You Never Erase, the append-only ledger, reversals and derived balances Finance Half a Point a Day, Gone, integer minor units, rounding and currency exponents Finance The Hold That Is Not Money Yet: authorisation, capture, clearing, settlement and chargebacks Finance Mark as read Saved in this browser, and to your account when you sign in.