Designing a Payment Wallet Like PhonePe / Venmo / Cash App
Difficulty: Advanced · Prerequisites: Saga Pattern, Event Sourcing, and Idempotency
TL;DR
A digital wallet is an accounting system disguised as a consumer app. Every transfer is a pair of debits and credits on a double-entry ledger. Money never moves without both sides of the entry being written atomically.
💡 Double-entry ledger = every movement of money is written twice, once as leaving one account and once as arriving in another, and the two halves must cancel out. If they don’t, the write is refused - which is what makes “we lost a rupee” structurally impossible here.
flowchart LR
APP["Wallet App"]
API["Wallet API"]
LEDGER["Ledger Service<br/>double-entry"]
DB[("Postgres<br/>ledger primary")]
CACHE[("Redis<br/>balance cache")]
BANK["External Bank<br/>UPI Cards"]
K["Kafka<br/>events"]
APP -->|"1. Initiate transaction"| API
API -->|"2. Post journal entry"| LEDGER
LEDGER -->|"3. Write ledger entry"| DB
LEDGER -->|"4. Refresh balance cache"| CACHE
API -->|"5. Charge via bank rail"| BANK
LEDGER -->|"6. Publish tx event"| K
In 3 sentences: Users load money from banks (async, webhook-confirmed), send to each other (instant, single DB transaction), and withdraw (async again). The core is a double-entry ledger in Postgres - every balance change creates both a debit and a credit line that sum to zero. Redis caches balances for fast reads; Kafka fans out events to notifications and analytics.
Understanding the Problem
👛 What is a payment wallet? A closed-loop or semi-closed-loop digital wallet lets users load money into a balance, send it peer-to-peer, pay merchants, and withdraw back to a bank. Examples: Paytm Wallet, PhonePe Wallet, Venmo, Cash App, Google Pay’s balance. Under the hood it’s an accounting system disguised as a consumer app - every “transfer” is a pair of debits and credits on a ledger, and every ₹1 or $1 moving in the app must correspond to real money sitting in a partner bank account.
Naive First Cut
30-second whiteboard sketch:
flowchart LR
APP["Wallet App"]
API["Wallet API"]
DB[("Users + Balances<br/>one table")]
BANK["Bank"]
APP --> API
API --> DB
API --> BANK
Discussion
Newest first