KatInterview

Design a Distributed Financial Ledger System

System DesignModel answer
HardModel answerSystem Designdistributed-systemsconsistencytransactions

Last updated

Build a strongly consistent, double-entry ledger handling concurrent writes, balance queries, and audit trails at scale.

You're building the core ledger for a payments platform that tracks money movements between customer wallets, merchant accounts, platform fees, and external bank accounts.

Design a system that:

  1. Records financial transactions with multiple legs (for example, a payment that debits a customer, credits a merchant, and credits a fee account)
  2. Maintains account balances that can be queried in real time
  3. Guarantees correctness: no duplicate charges, no lost money, balances always reconcile
  4. Handles concurrency: thousands of transactions per second, including many against the same hot accounts
  5. Supports auditability: full history, point-in-time balance reconstruction, and compliance reporting

Your design should cover:

  • Data modeling and the double-entry accounting model
  • API contracts for posting transactions and querying balances
  • Consistency guarantees and how you achieve them
  • Handling retries and preventing duplicate charges
  • Scaling to 10,000 transactions/sec with peaks at 50,000/sec
  • Managing hot accounts that receive tens of thousands of operations per second
  • Failure modes and recovery

Discuss trade-offs between consistency, latency, and throughput. Explain how you'd validate correctness continuously.

Hints

Hint 1

Every transaction must balance to zero within its currency—this is the core invariant to protect

Hint 2

Idempotency keys let clients safely retry without creating duplicate charges

Hint 3

Hot accounts like a platform fee collector become bottlenecks if modeled as a single row with a lock