Design a Digital Wallet System
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2021-07-21
Problem Statement
Design a scalable digital wallet system (like Paytm Wallet, PhonePe Wallet, or Amazon Pay Balance). The system should allow users to store money, transfer funds, and make payments in a secure and reliable way.
✅ Functional Requirements
1.<span></span>User Management
2.<span></span>Create and manage wallet accounts linked to users.
3.<span></span>Support KYC verification (basic vs. full wallet limits).
4.<span></span>Wallet Operations
5.<span></span>Add money to wallet (via UPI, bank account, or card).
6.<span></span>Check balance.
7.<span></span>Transfer money between wallet users.
8.<span></span>Pay merchants using wallet balance.
9.<span></span>Refunds & reversals for failed transactions.
10.<span></span>Transaction Handling
11.<span></span>Ensure atomicity of debit/credit operations.
12.<span></span>Maintain transaction history for auditing.
⚙️ Non-Functional Requirements
1.<span></span>Scalability → Handle millions of concurrent wallet transactions.
2.<span></span>Reliability → No double-spending; strong consistency guarantees.
3.<span></span>Low Latency → Balance checks and payments should be near real-time.
4.<span></span>Security → PCI-DSS compliance, fraud detection, and encryption.
5.<span></span>High Availability → System should remain available during peak traffic.
🔐 Constraints
1.<span></span>Wallet balance limit (e.g., ₹1,00,000 as per regulations).
2.<span></span>Transactions must be idempotent (retry-safe).
3.<span></span>Strong auditing and regulatory compliance.
🧱 Design Areas to Cover
1.<span></span>APIs → createWallet(), addMoney(), transfer(), getBalance(), payMerchant().
2.<span></span>Data Model → User, Wallet, Transaction entities.
3.<span></span>Architecture → Service-oriented design (Wallet Service, Payment Service, Transaction Service).
4.<span></span>Storage → SQL for strong consistency + caching (Redis) for balance reads.
5.<span></span>Concurrency → Locking mechanisms or optimistic concurrency to prevent race conditions.
6.<span></span>Scalability → Sharding wallets by user ID, message queues for async operations.
7.<span></span>Monitoring & Alerting → Detect fraud patterns, failed transactions, and latency issues.
👉 This HLD problem tests:
1.<span></span>Financial transaction handling (ACID properties, idempotency)
2.<span></span>Scalable and fault-tolerant design
3.<span></span>Security and compliance awareness