KatInterview

Build a Fault-Tolerant Money Transfer Ledger at Scale

System DesignModel answer
HardModel answerSystem Designsystem-designledgeracid

Last updated

Design a distributed ledger for account-to-account transfers that stays strictly consistent, avoids overdrafts and duplicate charges, and survives crashes at any point.

Scenario

You are designing the core of a payments platform in which customers move money between accounts. The platform handles millions of transfers a day across several regions. Losing a committed transfer is unacceptable, and so is letting the same funds be spent twice.

What the system must do

  • Show a customer the current balance of an account.
  • Move money from one account to another.
  • Return a paginated history of an account's transactions.

Qualities it must have

  • Correctness: Transfers are atomic and consistent. Money is never created or destroyed, and an account can never be overdrawn by racing requests.
  • Throughput: Many transfers run at the same time without corrupting state.
  • Durability: Once a transfer is confirmed, it survives machine, rack, and zone failures.
  • Availability: Balance lookups and transfers stay responsive under normal failures.

What your answer should cover

  1. Capacity estimate: Turn the volume into transactions per second, read/write ratio, and storage growth.
  2. API: Endpoints for transfers, balance, and history, including how clients can safely retry.
  3. Data model: Pick a storage technology and a schema, and justify it (relational vs. NoSQL, how atomicity across two accounts is achieved).
  4. Architecture: Service boundaries, replication, messaging, and any consensus or coordination you rely on.
  5. Concurrency control: How you stop two simultaneous debits from driving a balance below zero, and how you deal with extremely busy accounts.
  6. Cross-shard transfers: What happens when the two accounts live on different database shards.
  7. Failure handling: What state is the system in, and how does it recover, if a process dies halfway through a transfer?

Hints

Hint 1

Begin by writing down the invariants (total money is conserved, balances never go negative, a retried request is applied once) and check every design choice against them.

Hint 2

Treat an append-only set of debit/credit entries as the source of truth and the stored balance as a derived value updated in the same transaction. Think about a conditional update that fails when funds are insufficient.

Hint 3

For transfers spanning shards, compare a distributed transaction (2PC or distributed SQL) with a multi-step workflow using an in-flight holding account, an outbox, idempotent consumers, and a recovery job.