DesignTheSystem/dev
MEDIUM Low-Level Design (LLD) 11 automated tests

Design Digital Wallet (Low-Level Design)

Deposits, withdrawals and transfers that are safe to retry, with a full history. Focus: Idempotent money operations and a ledger.

DifficultyMEDIUM
Design focusIdempotent money operations and a ledger
Automated grading3 public + 8 hidden tests (11 total)
Phase 2 follow-upFee plans
LanguageTypeScript (OOP / Machine Coding)

Problem statement

Amounts are whole cents. Every operation carries a requestId chosen by the caller.

Retrying with a requestId that already succeeded must not move money again: it returns the original result (the balance after the first deposit or withdrawal).

A failed operation (unknown account, not enough money, bad amount) changes nothing and does not use up its requestId.

Functional requirements

  • createAccount(id) (an existing id throws); balance(id).
  • deposit(id, amount, requestId) and withdraw(id, amount, requestId) return the new balance.
  • transfer(from, to, amount, requestId) moves money; transferring to yourself throws.
  • history(id) lists entries { type, amount, requestId } in order, with types DEPOSIT, WITHDRAW, TRANSFER_IN and TRANSFER_OUT.

Required API & starter interface

Implement the TypeScript class interface below. You can add any helper classes, policies or strategies you need:

type EntryType = "DEPOSIT" | "WITHDRAW" | "TRANSFER_IN" | "TRANSFER_OUT";

class Wallet {
  createAccount(id: string): void {
    throw new Error("Not implemented");
  }

  deposit(id: string, amount: number, requestId: string): number {
    throw new Error("Not implemented");
  }

  withdraw(id: string, amount: number, requestId: string): number {
    throw new Error("Not implemented");
  }

  transfer(from: string, to: string, amount: number, requestId: string): void {
    throw new Error("Not implemented");
  }

  balance(id: string): number {
    throw new Error("Not implemented");
  }

  history(id: string): { type: EntryType; amount: number; requestId: string }[] {
    throw new Error("Not implemented");
  }
}

Public test cases

Your code runs against 3 public tests plus 8 hidden edge-case tests in a sandbox:

Deposit and withdraw (core)

var w = new Wallet();
w.createAccount("a");
assertEqual(w.deposit("a", 500, "r1"), 500);
assertEqual(w.withdraw("a", 200, "r2"), 300);

Retries do not double-charge (core)

var w = new Wallet();
w.createAccount("a");
w.deposit("a", 500, "r1");
assertEqual(w.withdraw("a", 100, "r2"), 400);
assertEqual(w.withdraw("a", 100, "r2"), 400);
assertEqual(w.balance("a"), 400);

Not enough money (edge)

var w = new Wallet();
w.createAccount("a");
assertThrows(function () { w.withdraw("a", 1, "r1"); });

Design & structure checks

Beyond passing tests, the grader inspects your class structure for clean object-oriented design:

  • Fee plans are separate policies: New plans (a cap, a free monthly allowance) should be new classes, not new branches in transfer().
  • Every change is a ledger entry with a named type: A history of typed entries is how real wallets explain and audit every balance.

Phase 2: Change request

In real interviews, the follow-up tests whether your design is extensible. After your first version passes all 11 tests, you unlock the change request: Fee plans.

Pair with High-Level System Design

Ready to scale Digital Wallet across distributed servers? Try the matching HLD simulator problem: Design Digital Wallet & Payment Ledger.

Relevant low-level design lessons

More low-level design problems