KatInterview

Building a Digital Wallet Transfer Service

System DesignModel answer
MediumModel answerSystem Designfinancial-systemsdistributed-systemstransactions

Last updated

Design a system that enables users to transfer funds between accounts with correct balances, handling failures, retries, and concurrent operations.

You're building a digital wallet service where users maintain balances and transfer funds to each other. Your system must guarantee that every dollar is accounted for correctly, even when servers crash, requests time out, or multiple operations happen simultaneously.

Your design should handle:

  • Users creating accounts and checking their current balance
  • Initiating fund transfers between two users
  • Viewing a complete transaction history
  • Surviving system failures without losing or duplicating money
  • Handling retried requests that may arrive multiple times
  • Processing simultaneous transfers from the same account

What to Design

Provide a complete architecture including:

  1. API contracts for the key operations
  2. Data models for accounts, transactions, and balance tracking
  3. State management for transfers as they progress
  4. Correctness guarantees preventing money creation or loss
  5. Concurrency control for simultaneous operations
  6. Failure handling and system recovery mechanisms
  7. Production considerations beyond a simple in-memory prototype

Assumptions

  • Single currency system for now
  • Transfers must be exact: no money appears or vanishes
  • Network issues cause clients and background jobs to retry operations
  • Multiple transfers can be initiated from one account at the same time
  • Bank integration and funding sources are handled elsewhere

Questions to Consider

  • Should transfers complete instantly or go through approval stages?
  • Can recipients use incoming funds before they finalize?
  • How do you distinguish between available funds and funds in flight?
  • What fraud prevention and compliance features are needed?

Hints

Hint 1

Think about immutable records - once money moves, keep a permanent log rather than just updating numbers

Hint 2

Consider how you'll make transfer creation idempotent so retries don't create duplicate transactions

Hint 3

Design for pessimistic locking or optimistic versioning to prevent overdrafts when concurrent transfers attempt to spend the same balance