Design a Digital Wallet: Junior, Senior, and Staff Answers
When you hear design a digital wallet, the interviewer is looking for three things: how you think about high-throughput, low-latency financial flows; how you keep data consistent and secure; and whether you can reason about operational concerns at scale.
Core requirements and driving numbers
| Requirement | Typical value (hedged) |
|---|---|
| Peak write load | ~100 k transactions per day → about 1.2 transactions per second |
| Read-heavy queries | Balance checks, transaction history – roughly 10× writes → ~12 reads/sec |
| Latency target | <200 ms for user-visible operations |
| Durability | Must survive node failures; no loss of money |
| Security | PCI-DSS level controls, encryption at rest and in transit |
These numbers set the scale for the components you choose. A design that can handle a few dozen requests per second is fine for a junior answer; a senior answer shows you can grow to millions of requests per day, and a staff answer demonstrates you can keep the system safe and cheap at that scale.
Request path, one hop at a time
1. API Gateway → Auth Layer
The client (mobile/web) hits an Amazon API Gateway endpoint. The gateway forwards the request to a Lambda authorizer that validates a JWT issued by an OAuth provider (e.g., Cognito). This keeps the path stateless and offloads auth scaling to managed services.
2. Lambda → Business Logic
A thin AWS Lambda function parses the request and performs basic validation (amount > 0, user has sufficient balance). For a charge operation it writes a record to a Kafka topic on Amazon MSK; for a balance query it reads from a cache.
3. Kafka → Transaction Processor
A consumer group of EC2 instances (or Fargate tasks) pulls the transaction record from MSK. It runs the core business logic: debit source account, credit destination, write audit logs. The processor writes the updated balances to Amazon DynamoDB in a single transactional write, guaranteeing atomicity.
4. DynamoDB → Cache
Successful writes trigger a DynamoDB Streams event that updates an ElastiCache for Redis entry for the affected accounts. Subsequent balance checks hit the cache first, falling back to DynamoDB on a miss.
5. S3 & CloudFront for static assets
User-facing UI assets (logo, help PDFs) are stored in Amazon S3 and delivered via CloudFront. This is unrelated to the transaction path but rounds out the ecosystem.
Data model (simplified)
-- Users table (DynamoDB) – partition key: user_id
User { user_id PK, email, phone, created_at }
-- Wallet table – PK: user_id, SK: wallet_id
Wallet { user_id PK, wallet_id SK, balance, currency, updated_at }
-- Transaction table – PK: txn_id, attributes: src_wallet, dst_wallet, amount, status, ts }The transaction table is written once per operation. The wallet table holds the current balance; it is updated transactionally together with the transaction record to keep the two in sync.
What a complete junior answer covers
| Element | Junior level |
|---|---|
| Scope | Lists functional requirements (add money, pay, view balance) and non-functional goals (latency, durability). |
| Architecture diagram | Shows API Gateway → Lambda → DynamoDB. |
| Data model | Simple tables for users, wallets, transactions. |
| Consistency | Mentions DynamoDB transactional writes for atomic debit/credit. |
| Security | Talks about TLS, JWT auth, and IAM roles. |
| Scaling | Says "add more Lambda concurrency, increase DynamoDB read/write capacity". |
Missing pieces at this level: caching, async processing, and detailed failure handling.
What a senior answer adds
| Element | Senior level |
|---|---|
| Caching | Introduces ElastiCache for fast balance reads, explains cache-aside pattern. |
| Async pipeline | Uses MSK to decouple request ingestion from processing, enabling retries and back-pressure handling. |
| Rate limiting | Adds API Gateway usage plans or a token bucket in Lambda to protect against abuse. |
| Monitoring | CloudWatch metrics, X-Ray tracing for request latency, and DynamoDB TTL for stale data. |
| Data partitioning | Discusses using a hash of user_id as DynamoDB partition key to spread load. |
| Cost awareness | Shows how on-demand Lambda and provisioned DynamoDB can be tuned. |
The senior answer still keeps the core flow simple but shows you can improve throughput and observability without redesigning the whole system.
What a staff answer adds
| Element | Staff level |
|---|---|
| Failure modes | Discusses partial failures in MSK consumers, DynamoDB throttling, and cache invalidation races. Proposes idempotent transaction IDs and a dead-letter queue (SQS) for unrecoverable records. |
| Operational tooling | Uses AWS Config rules, GuardDuty alerts, and automated backups (DynamoDB point-in-time recovery, S3 versioning). |
| Cost optimization | Shows how to leave spiky or idle paths on on-demand Lambda, keep provisioned concurrency for latency-sensitive paths with steady traffic, use DynamoDB auto-scaling, and reserve capacity for steady traffic. |
| Trade-off defense | Argues for DynamoDB over Aurora because of its built-in global tables for multi-region read latency, despite higher per-GB cost. |
| Global latency | Mentions multi-region read replicas via DynamoDB Global Tables and CloudFront edge caching for static UI. |
| SLA & compliance | Outlines PCI-DSS controls: encryption at rest (KMS), audit logs (CloudTrail), and regular pen-testing. |
A staff answer treats the wallet as a production service that must run 24/7, survive data-center outages, and stay within a reasonable budget.
Common mistakes that sink this question
- Skipping security – forgetting encryption, token validation, or audit logging.
- Over-engineering the data model – adding unnecessary joins or relational tables when DynamoDB’s single-table design suffices.
- Ignoring idempotency – duplicate transaction records cause double-spending.
- No caching strategy – reading balance directly from the database for every request leads to high latency.
- Forgetting operational concerns – no monitoring, no alerting, no backup plan.
- Mis-estimating scale – assuming 100 k/day is "tiny" and not planning for growth to millions.
Avoiding these pitfalls signals that you understand both the design and the real-world constraints of a financial service.
How to practice this
- Study the worked double-entry ledger design in the System Design AI library; a ledger is the core of a wallet. Click each component to read its notes.
- Draft your own canvas on the practice board: start with the API layer, add async processing, then flesh out the data model and cache.
- Run the AI coach on your canvas. Review its feedback on missing security checks, scaling assumptions, and operational gaps, then iterate.
Questions people ask
What latency can a Lambda-based wallet achieve?
With API Gateway, a warm Lambda, and a cache hit, end-to-end latency can be under 150 ms. Cache misses add a DynamoDB read (~30 ms) and still stay below 200 ms.
Why choose DynamoDB over Aurora for balances?
DynamoDB gives single-digit millisecond latency, automatic horizontal scaling, and transactional writes that simplify atomic debit/credit without managing a relational lock manager.
How do you prevent double-spending?
Generate a globally unique transaction ID and store it as the primary key. The processor treats a repeat of the same ID as a duplicate and discards it, ensuring idempotency.
What is the role of MSK in this design?
MSK decouples request ingestion from processing, provides replayability, and lets the consumer pool scale independently. It also offers a natural place for a dead-letter queue via SQS.