Project 09
Banking ledger and money transfer
Financial correctness
Brief
A double-entry ledger: accounts, balances, internal transfers, holds, statements — the system of record where correctness beats every other quality attribute.
Why "after Part 7" when the key topics are in Part 5: the ledger is designed as an append-only journal — immutable entries, state derived from the log — and that framing comes from Part 7 (→ 120 at concept level), even though the implementation is a plain relational schema.
Targets
2k transfers/sec · the books always balance (entries sum to zero, always) · no negative balance without an overdraft facility · 7-year immutable history · RPO = 0.
Must cover
- Transactions with correct isolation (→ 70).
- Reconciliation — the ledger against external statements and internal invariants (→ 81).
- Double-entry bookkeeping and ledger invariants (P).
- Reversals instead of edits — corrections are new entries, never updates (P).
Design challenges
- Double-entry model (→ 59, 69): immutable journal entries; balances derived — never
UPDATE balance = balance - xas the source of truth. - Transfer atomicity in one database: isolation level chosen and defended against write skew (→ 70).
- Balance reads at scale: derived/cached balances vs. recomputation, and the exact consistency guarantee offered for "available balance" (→ 129 — ahead, Part 8).
- The hot-account serialization problem — a merchant during a sale (→ 88, and Project 7's techniques).
- The ADR against distributing the ledger (→ 143 — ahead, Part 9) — and where 2PC or saga would appear if a transfer had to span two ledger instances (→ 138–139).
- Immutability and audit: append-only enforcement, reversing entries, RPO = 0 replication (→ 72; → 171 — ahead, Part 10; → 195 — ahead, Part 12).
Out of scope
External settlement rails, foreign exchange, regulatory reporting pipelines.