Design a Digital Wallet
Understanding the Problem
👛 What is a digital wallet? A digital wallet holds a balance of money on behalf of a user. Users top it up from a card or bank account, spend it at merchants, send it to other users and withdraw it back to a bank. PayPal balances, Apple Cash, Alipay, GrabPay and in-game currencies all work this way. The provider holds the real money in its own bank accounts, and the wallet is the record of how much of it belongs to each user.
A common variant is a custodial crypto wallet, like the wallet inside Coinbase or Binance. The user's coins sit in wallets the company controls, and the company keeps an internal record of who owns what. It's the same problem at the core (balances, transfers, no double-spends), with a very different edge: deposits and withdrawals happen on a public blockchain instead of through banks. We'll design the fiat wallet first and cover crypto custody in a deep dive.
Note the difference from a digital wallet like Apple Pay or Google Pay, which stores card credentials on the phone and passes them to merchants. That has no balance of its own; it's a card tokenization problem. If your interviewer says "digital wallet," check which one they mean. This post covers the stored-value kind.
Functional Requirements
Core Requirements
- Users should be able to add money from a card or bank account, and withdraw money to a bank account.
- Users should be able to send money to another user, and pay a merchant from their balance.
- Users should be able to see their balance and their transaction history.
Below the line (out of scope)
- Requesting money, splitting bills and social feeds. Those are covered in /system-design/p2p-payments.
- Cards linked to the wallet (a physical debit card that spends the balance).
- Currency exchange between wallets in different currencies.
- Rewards, cashback and interest.
Non-Functional Requirements
Ask for scale. For our design: 50 million users, 10 million daily actives, and about 20 million money movements a day, most of them transfers and merchant payments.
Core Requirements
- A user's balance must never go negative, and money must never be created or lost: no double-spends, no half-finished transfers.
- Every operation must be idempotent, so retries from flaky mobile networks can't move money twice.
- Transfers between users should complete in under a second, end to end.
- The system should be highly available (99.99%), and favor consistency over availability for balance changes.
- Every movement must be auditable and reconcilable with the bank accounts that hold the real money.
Below the line (out of scope)
- Global multi-region writes. Each user is homed in one region.
- Detailed regulatory work (money transmitter licenses, safeguarding rules), though they shape some decisions, which we'll mention.
Back of the envelope: 20M movements a day is about 230 per second on average. Even a 10x peak is ~2,300/s. Each transfer writes a transaction and two or three entries, so under 10k row writes per second at peak. A single well-tuned Postgres primary can come close to this, and a handful of shards handles it comfortably with room to grow.
So throughput isn't what makes this hard. Correctness under concurrency is: two requests spending the same $50 at once, a retry that arrives after the original succeeded, a bank withdrawal that fails three days after we debited the wallet.
When the numbers say "this fits on a few database shards," say so. Interviewers like candidates who size the system honestly and then spend their time on the parts that actually break.