The interview problem

Practice prompt

Design an internal ledger for a prepaid wallet. Support deposits, transfers between users, spending holds and refunds. Prevent concurrent overspending and duplicate posting, retain an audit trail and reconcile the ledger with an external payment processor.

Original software-design practice, not a reported interview. Examples use a simplified single-currency wallet and do not prescribe a production chart of accounts or regulatory treatment. Technical sources retrieved September 27, 2026.

1. Write invariants before choosing storage

Define the ledger from the platform's perspective. Customer wallet balances represent liabilities the platform owes customers; settlement cash is an asset. Each posted journal transaction must balance total debits and credits within its currency. Require at least two valid entries, compatible account currencies, positive amounts and checked arithmetic to prevent overflow. Use integer amounts with a declared currency scale, never binary floating point for posted money.

Additional invariants matter: an operation posts at most once, an account cannot spend more than its permitted available balance, and posted entries cannot be silently edited. A balanced transaction can still use the wrong customer account or wrong amount. Double entry detects some classes of error, not all business mistakes.

Assume no overdrafts, no foreign exchange and no interest. Clarify settlement finality, chargebacks and fees before expanding the model. External payments can remain pending or uncertain even when the internal database is healthy.

2. Work through a balanced wallet transfer

When a settled $100 deposit funds Alice's wallet, debit settlement cash $100 and credit Alice's wallet liability $100. For an internal $30 transfer from Alice to Bob, debit Alice's liability $30 and credit Bob's liability $30. Cash remains $100; liabilities are now Alice $70 and Bob $30. Both journal transactions balance.

A later $10 reversal of that transfer, when permitted by the business policy, adds a new linked journal: debit Bob's liability $10 and credit Alice's liability $10. Do not modify the original $30 entries. The resulting liabilities are Alice $80 and Bob $20, still totaling $100.

A refund involving a processor is a separate workflow. An internal adjustment does not prove cash moved externally. If Bob already spent his balance, the requested reversal may be unavailable under the no-overdraft assumption; do not force the example through by creating an unexplained negative balance.

3. Commit the journal and balance decision together

Use an authenticated ledger API, a transactional posting service, an append-only journal, account balance projections and an outbox for downstream notifications. Journal headers carry operation identity, currency, business reference, creation time and reversal links. Entries carry account, debit or credit direction and integer amount.

For a transfer, validate the account types and permissions, claim a unique tenant-scoped operation key, lock the relevant balance rows in a deterministic order, check available funds and insert the complete balanced journal. Update balance projections and the outbox in the same database transaction. A duplicate key with identical parameters returns the original result; a changed payload is an error.

Use a database-enforced posting procedure or equivalent transaction boundary that prevents partial journals. A row-level check alone cannot generally enforce that the sum across an arbitrary set of entry rows balances. Restrict direct writes so callers cannot bypass the posting path. Rebuildable projections help audit, but spend decisions must use a transactionally consistent balance, not a delayed analytics view.

Explicit row locking or a suitable serializable transaction can protect concurrent decisions. Retry the complete transaction on serialization failure using the same operation identity. Do not issue external processor requests inside a database transaction that may be retried.

4. Separate reserved funds from posted movement

For a separate hold example, assume Alice has a posted wallet balance of $100 and an active $60 hold. Available funds are $40. A concurrent request for another $50 hold must fail even though posted balance alone still reads $100. Create or modify the hold atomically with the available-funds check.

If the merchant makes a final capture of $45 from the $60 hold, atomically post a $45 transfer to the merchant payable account, close the $60 reservation and release the unused $15. Alice's posted balance becomes $55 and her available balance is $55 if no other holds exist. Releasing the hold before posting the capture in separate transactions could temporarily expose money for double spending.

Model hold capture, cancellation and expiry as mutually consistent state transitions with stable operation IDs. A capture racing an expiry must have one valid outcome. If partial captures are allowed, track the remaining reserved amount and enforce the original limit. Pending holds are not silently treated as completed settlement entries.

5. Reconcile external movement without guessing

Use a payment-workflow record and durable outbox to initiate external operations. Link processor IDs and business operation IDs to the ledger, but distinguish “requested,” “confirmed” and “unknown.” A timeout may occur after the processor accepted the request. Use supported idempotency and authoritative lookup, then reconcile unresolved cases rather than blindly creating another payment.

Match processor reports to ledger references, amounts, currency and settlement dates. Timing differences, fees, partial refunds and duplicate reports need explicit categories. An unmatched total is an investigation item, not permission to insert a balancing entry merely to make the numbers agree.

Keep authorization and financial posting rules outside untrusted webhook payloads. Verify event authenticity, deduplicate events and retrieve authoritative state where necessary. A processor event arriving twice must not credit a wallet twice. Different event IDs can describe the same payment, so enforce uniqueness on the business posting identity as well as deduplicating transport events. Preserve the evidence and operator decisions for any manual correction.

6. Scale around the consistency boundary

Assume 1,000 journal transactions per second, averaging four entries of 160 bytes each. Entry payload is 640 KB/second, or 55.296 GB/day. Three copies require 165.888 GB/day before headers, indexes, write-ahead logs and backups. Account histories should use cursor pagination and indexed account/time access, not scan the complete journal.

Hot accounts, such as a single merchant clearing account, can serialize otherwise independent transfers. Start with a clear transactional boundary and measure lock contention. Partitioning a logical clearing balance into approved subaccounts may distribute contention, but aggregation and reconciliation must preserve its meaning.

Sharding by account does not make a transfer between shards atomic. Options include keeping a ledger partition's accounts together, using a database with appropriate distributed transactions, or representing cross-partition movement through explicit pending and clearing states. A saga with compensation provides a different contract from an instant atomic transfer; explain that difference rather than claiming eventual balance prevents temporary overspending.

7. Prove invariants under failure

Test two simultaneous spends against the same funds, duplicate submissions with different payloads, crashes before and after commit, capture/expiry races and repeated external events. Verify no partial journal, no duplicate business posting and no unauthorized negative available balance. Recompute projections from the journal and compare results.

Back up and restore to a consistent transaction boundary. Reconcile restored state with external operations that occurred after that point before resuming spending. Failover with lost committed entries can recreate spendable funds or lose liabilities; define durability and recovery objectives explicitly.

Foundation: explain why debits do not always decrease an account. Senior: make a hold capture atomic. Staff: support cross-shard transfers while stating precisely when funds are available.

Score 0–2 each for balanced entries, concurrency control, hold semantics, external reconciliation and recovery evidence. Full marks require separating a balanced journal from a correct business transaction. Continue with usage accounting and integration reconciliation.

Sources and next steps

The wallet scenario, posting protocol, hold example and capacity calculations are original. The design is not a claim that any named database automatically enforces every application invariant.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.