KatInterview

Designing a High-Throughput Financial Ledger Service

System DesignModel answer
MediumModel answerSystem Designsystem-designdatabase-designconcurrency

Last updated

Design an accurate, idempotent, and highly concurrent banking ledger database schema and transaction pipeline.

Create a data architecture and service layer for a core banking application handling deposits, withdrawals, balance checks, and transaction auditing.

System Requirements

  1. Strict Data Integrity: Prevent negative balances on withdrawal operations unless explicitly authorized. Ensure atomic state updates.
  2. Concurrency Controls: Support high volume without introducing race conditions, dirty reads, or lost updates under concurrent access.
  3. Idempotent API: Ensure client-side retries (due to dropped connections or timeouts) do not execute duplicate operations or cause double-spending.
  4. Immutable Audit Log: Every financial operation must produce an append-only transaction record for regulatory compliance and auditability.

Key Deliverables

  1. Define a relational database schema (including accounts and transactions tables).
  2. Outline the step-by-step logic for a withdraw(account_id, amount, idempotency_key) function. Include code/pseudocode showing transaction boundaries and lock management.
  3. Detail how your solution handles floating-point errors, high overall system throughput (10,000+ operations/sec), and idempotency key misuses.

Hints

Hint 1

Avoid floating point types for currency; represent amounts using integer values of the smallest monetary subunit (e.g., cents).

Hint 2

Combine reading, validating, and mutating state inside a single database row lock or atomic UPDATE query to prevent lost updates under concurrency.

Hint 3

Use a unique database constraint on (account_id, idempotency_key) to safely handle concurrent identical requests.