← Lessons

quiz vs the machine

Silver1080

System Design

The Double Entry Ledger Deep Dive

Why every money movement is recorded as two equal and opposite postings.

4 min read · intro · beat Silver to climb

What double entry means

A double entry ledger records every economic event as at least two postings that sum to zero. One account is debited and another is credited by the same amount. Money is never created or destroyed inside the system, it only moves between accounts.

Why this matters

  • The invariant that all postings sum to zero gives you a cheap correctness check.
  • Each balance can be recomputed from the raw postings, so the ledger is self auditing.
  • A bug that loses money becomes visible because the books no longer balance.

A concrete example

When a user funds a wallet with ten dollars, you debit the user cash account and credit the user wallet account. The total across both accounts is unchanged.

Practical rules

  • Always write both legs in one atomic transaction.
  • Use a single currency per posting and never mix units in one leg.
  • Treat amounts as integer minor units like cents to avoid float drift.

Key idea

Every money movement is two equal and opposite postings, and the books must always balance to zero.

Check yourself

Answer to earn rating on the learn ladder.

1. What invariant does a double entry ledger enforce?

2. Why store amounts as integer minor units?