System Design
Advanced

Design a Payment Ledger

Design immutable financial records, balances, reconciliation, and audit trails.

45 min
3 sections
ledger
payments
finance
1
2
3

01. Use append-only accounting

Section 1 of 3

Financial systems should record facts, not overwrite history. Use immutable journal entries with balanced debits and credits. Derived balances can be cached, but the ledger is the source of truth.

text
Journal entry:
- entry_id
- transaction_id
- created_at
- status

Lines:
- account_id: customer_cash, debit: 10000, credit: 0
- account_id: merchant_payable, debit: 0, credit: 9700
- account_id: platform_fee, debit: 0, credit: 300

Invariant: sum(debits) == sum(credits)
Back to Course