Dev Skills

Design a payment system with a double-entry ledger

Design the payment system behind a marketplace. Customers pay, money is held, sellers are paid out, refunds happen, and the books must balance exactly. An external payment provider holds the real money.

About this problem

“Design a payment system with a double-entry ledger” is a hard-level problem in the money and correctness family. Being fast is worthless if the number is wrong, and every mistake is somebody's actual money.

The key challenge: A person is waiting to find out whether their payment worked, and that is the only part with no slack. Everything behind it (capture, ledgers, payouts, reconciliation) has hours, and the design uses those hours to be correct.

Time budgets: Authorisation: seconds. Capture: minutes. Settlement and payout: hours to days.

The worked solution for Payment ledger goes through why those budgets shape the design, stage by stage.

Before you start

You will work this in five timed stages. Here is what each one asks you to think about. None of it is the answer; the answers unlock in the workspace below once you have written your own.

  1. Stage 1 · Requirements · 5 min
    • Are you holding the money, or is a provider? That changes most of the design.
    • One currency or many? Multi-currency is a whole extra system.
    • What is the worst acceptable outcome — losing money, or refusing a valid payment?
  2. Stage 2 · Actors and lifecycle · 6 min
    • The provider is an actor with its own outages and its own opinions.
    • What does the system decide silently on everyone's behalf?
    • What happens when you call the provider and never get a reply?
  3. Stage 3 · Numbers · 6 min
    • Payment volume is small compared to almost anything else. Say so.
    • How many ledger rows does one payment create?
    • What does one incorrect transaction cost to resolve?
  4. Stage 4 · High-level design · 12 min
    • What does a double-entry ledger look like as a table?
    • How does one action change our database and the provider together?
    • What runs nightly, and what does it compare?
  5. Stage 5 · Deep dive and tradeoffs · 14 min
    • The provider call timed out. Walk through what happens next.
    • Reconciliation finds 14 mismatches this morning. What now?
    • How do you deploy a change to this safely?
Prefer to read first? The worked solution, end to end →

Work it through

Five stages, gated. You write your answer for each stage before its model answer unlocks. That is the core of the method.

Loading your progress…

Done all five? The diagrams, numbers, trade-offs and follow-ups for this problem are on the worked solution page, to check your own design against.

Before you leave
Try this problem again in a week without reading anything. Comparing what you write then with what you wrote today shows you what stuck.
Stuck, or new to this?Read the full worked solutionAll five stages end to end, with the diagrams and the costs, written out the way you would say it. Best read after you have had a go.Read it →

How it is really built

Write your own answer first. Then read how teams who run this at scale describe it. Their constraints were real, and the write-ups often say what their choices cost.