Banking Ledger And Transaction Semantics
Asked of: Software Engineer
Last updated

What's being tested
These questions test whether you can model money movement as a set of transactional invariants, not merely mutate an account balance. You should demonstrate double-entry ledger design, atomic transfers, idempotent APIs, concurrency control, validation, and immutable auditability. Coinbase cares because a race condition, duplicate retry, or incorrect decimal calculation can create real customer loss and regulatory exposure; the interviewer is probing whether your design remains correct during failures and concurrent requests.
Core knowledge
-
A double-entry ledger records every movement as balanced postings: for each transaction, . A transfer from account A to B creates at least two immutable entries, preserving auditability and enabling reconstruction.
-
Treat the journal as the source of truth and balances as a projection or cached summary. An account’s balance is ; periodically recompute projections from journal entries to detect corruption or missed updates.
-
Use integer minor units or exact decimal arithmetic, never binary floating point. Store cents, satoshis, or asset-specific base units with an explicit currency/asset; validate multiplication and addition for overflow before committing.
-
A transfer must be atomic: validation, debit posting, credit posting, and idempotency-record creation commit in one database transaction. If any step fails, none becomes visible. In
Postgres, this usually means one transaction with appropriate constraints. -
Enforce concurrency control around available funds. Row locks such as
SELECT ... FOR UPDATE, optimistic version checks, orSERIALIZABLEisolation prevent two withdrawals from both spending the same balance; choose based on contention and retry cost. -
Separate available, pending, and settled balances when operations can be asynchronous. A withdrawal hold should reduce spendable funds without pretending the final settlement has occurred; state transitions must be explicit and valid.
-
Make mutation APIs idempotent with a client-supplied idempotency key scoped to an account or operation type. Persist the key with the resulting transaction and request parameters; a retry returns the original result, while reuse with different parameters fails.
-
Define invariants before selecting storage: no account becomes negative unless overdrafts are explicitly supported, every posting references valid accounts, a transaction balances per asset, and finalized entries cannot be edited or deleted.
-
Use database constraints for local correctness: foreign keys, nonnegative amounts, unique
(account_id, idempotency_key), asset consistency, and check constraints. Application validation improves errors, but constraints protect against races and buggy callers. -
Design read APIs around consistent snapshots and indexed access patterns. Index
(account_id, created_at, transaction_id)for history pagination; prefer cursor pagination over offsets, which become expensive and unstable as rows change. -
Keep audit trails immutable. Corrections are compensating entries, not updates to historical rows; record actor, request ID, timestamps, reason, and correlation IDs so support and reconciliation can trace every change.
-
Distinguish database commit from external settlement. A bank or blockchain call cannot generally participate in the same ACID transaction, so model pending, submitted, confirmed, failed, and reversed states with retry-safe workers and reconciliation.
Worked example: Design a basic banking system
For “Design a basic banking system,” I would first clarify supported operations, currencies, overdraft policy, expected throughput, consistency requirements, and whether transfers are internal or involve external institutions. I would state that internal transfers require atomic, strongly consistent balance effects, while external settlement is asynchronous and stateful. I would organize the design around the account and immutable ledger schema, transactional transfer APIs, concurrency/idempotency controls, and auditability plus operational recovery. The transfer endpoint would validate the request, acquire deterministic locks or use serializable isolation, create balanced postings, persist the idempotency result, and commit once. I would explicitly choose a journal as the source of truth with a balance projection for fast reads, accepting projection-rebuild complexity in exchange for auditability. I would also define failure behavior: retries return the original result, while a crashed external operation is reconciled from provider status rather than blindly repeated. If I had more time, I would add authorization boundaries, key rotation, reconciliation jobs, archival strategy, and load-test scenarios for hot accounts.
A second angle
For “Design an in-memory banking system,” the same invariants apply, but durability, crash recovery, and distributed coordination may be intentionally out of scope. A map from account ID to account state can provide average lookup, while a mutex or single-threaded event loop serializes mutations. The main challenge shifts toward API semantics, invalid-input handling, deterministic operation ordering, and testable transaction behavior. I would still use integer amounts, idempotency semantics where retries matter, and an append-only in-memory event list if history is required. I would clearly state that process restart loses state unless snapshots or durable storage are added.
Common pitfalls
Pitfall: Treating a transfer as
balanceA -= amount; balanceB += amountwithout a transaction allows partial updates, lost writes, and double spending under concurrent requests. Model balanced postings and commit all effects atomically.
A tempting communication mistake is jumping directly into tables or frameworks without clarifying whether negative balances, pending states, and external transfers are allowed. State assumptions early, then explain how changing each assumption affects the design.
A depth mistake is saying “use a distributed lock” or “make it eventually consistent” without explaining correctness. For a financial mutation, name the isolation or locking strategy, idempotency-key storage, retry behavior, and invariant that the mechanism protects.
Connections
An interviewer may pivot to ACID isolation levels, outbox/inbox patterns, event sourcing, reconciliation, or authorization and fraud-prevention boundaries. Be ready to explain why exactly-once effects are usually achieved through durable idempotency and transactional state, not by assuming the network delivers exactly once.
Further reading
-
Designing Data-Intensive Applications — Martin Kleppmann’s treatment of transactions, consistency, replication, and event-driven systems.
-
Stripe: Idempotent Requests — concrete production semantics for safely retrying mutation APIs.
-
Martin Fowler: Event Sourcing — useful background on reconstructing state from immutable events.
Practice questions
- Design an in-memory banking systemCoinbase · Software Engineer · Online Assessment · medium
- Design a bank account ledgerCoinbase · Software Engineer · Online Assessment · hard
- Implement a Simple Banking LedgerCoinbase · Software Engineer · Onsite · medium
- Implement banking ops: transfer, top-k, cashback, mergeCoinbase · Software Engineer · Online Assessment · medium
- Design a basic banking systemCoinbase · Software Engineer · Onsite · hard
- Implement bank balance operationsCoinbase · Software Engineer · Technical Screen · medium
- Implement bank account with cashbackCoinbase · Software Engineer · Technical Screen · medium
Related concepts
- Banking Ledgers And Cashback OperationsSystem Design
- Transactional Banking System DesignSystem Design
- Payment Processing And Ledger SystemsSystem Design
- Payment Ledgers, Reconciliation, And State MachinesSoftware Engineering Fundamentals
- Distributed System Design For Ledgers And CountersSystem Design
- Wallets, Payments, And Refund LedgersSystem Design