Design a Ledger System
Understanding the Problem
📒 What is a ledger? A ledger is the record of every movement of money between accounts. Every payment, fee, refund, payout and adjustment a fintech company makes ends up as an entry in it, and every balance it shows (a merchant's available funds, a user's wallet, the company's revenue) is computed from those entries. If the ledger is wrong, the company doesn't know how much money it has or owes. Stripe-style platforms, banks, wallets and marketplaces all run one at their core.
You'll hear this as "design a ledger," "design a double-entry accounting system," or "design the balance service for a payments company." They're the same thing. Some interviewers start from the bookkeeping side (debits and credits); others start from the systems side (balances under concurrency, hot accounts). A strong answer covers both.
Double-Entry in Five Minutes
Double-entry bookkeeping has been around for centuries for a simple reason: it makes errors visible. Money is never created or destroyed, only moved, so every transaction records at least two entries, and the debits equal the credits.
Each account has a type, and the type says which side increases it:
| Account type | Examples | Increased by |
|---|---|---|
| Asset | Cash at our bank, money a card processor owes us | Debit |
| Liability | Balances we owe merchants or users | Credit |
| Revenue | Fees we earn | Credit |
| Expense | Processing costs we pay | Debit |
| Equity | Owner's capital | Credit |
Here's what a $100 card payment for a merchant, with a $3 fee, looks like:
Transaction: payment pay_456 captured
Debit processor_receivable 100.00 (asset: the processor owes us)
Credit merchant_m42_balance 97.00 (liability: we owe the merchant)
Credit fee_revenue 3.00 (revenue: we earned a fee)
-------
Debits 100.00 = Credits 100.00
Transaction: processor settles to our bank
Debit cash_operating 100.00
Credit processor_receivable 100.00
Transaction: payout to merchant
Debit merchant_m42_balance 97.00
Credit cash_operating 97.00
Two useful consequences. First, if you add up every account's balance with the right signs, the total is always zero. If it isn't, there's a bug. Second, you can answer "where did the money go?" by following entries, because nothing moves without a matching entry somewhere else.
If your interviewer isn't an accountant, keep it to "every transaction has balanced debits and credits, and balances are derived from entries." Then show one worked example like the one above. That's enough to make everything else in the design concrete.
Functional Requirements
Core Requirements
- Internal services (payments, payouts, billing) should be able to record a transaction made of balanced entries, atomically.
- Clients should be able to read an account's balance: the current balance, the available vs pending split, and the balance at any past time.
- Clients should be able to list an account's entries (its history or statement).
- Finance should be able to reconcile the ledger against external records (bank statements, processor settlement reports).
Below the line (out of scope)
- Generating formal financial statements (income statement, balance sheet). We'll make the data available; accounting tools build those.
- Tax calculation and regulatory reporting.
- Foreign exchange pricing. We'll handle multi-currency entries, but not where the rates come from.
Non-Functional Requirements
Ask for scale. For our design: a Stripe-style platform recording 200 million transactions a day, averaging 3 entries each, with a 10x peak during big shopping days.
Core Requirements
- The ledger must never lose or duplicate an entry, and every transaction must balance. Durability and correctness come first.
- History must be immutable and auditable. Nothing is edited or deleted; mistakes are fixed by new entries.
- Balance reads must be strongly consistent where they gate money (can this user spend $50?), and can be slightly stale for display.
- The system should sustain ~25k transactions/s at peak with write latency under ~50 ms, even when many transactions touch the same account.
- Data must be retained for many years (often 7 or more, depending on regulation).
Below the line (out of scope)
- Sub-millisecond latency of the kind an exchange's matching engine needs.
- Cross-region active-active writes to the same account.
The numbers: 200M transactions/day is about 2,300/s average and ~23k/s at peak, or ~70k entry rows per second. At ~200 bytes per entry with indexes, that's about 600M rows and ~120 GB a day, or ~45 TB a year, kept for years. That's big enough to shard and to tier old data to cheaper storage.
The number that shapes the design is less obvious. In the example above, every payment credits fee_revenue. If that account's balance lives on one row that every transaction updates, all 23k/s transactions serialize on a single row lock. A relational database manages somewhere around a thousand updates per second to one row before latency climbs. So hot accounts, not total throughput, are the bottleneck.