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) |
|---|---|
| Average write load | ~100 k transactions per day → about 1.2 transactions per second (say 3–4 at a 3× peak) |
| 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, known wallet). It does not decide whether the balance is enough: a check here would race with other payments still in the queue, so the processor makes that check atomically when it writes. 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 with conditions (source balance ≥ amount, transaction ID not seen before), so the debit, the credit and the duplicate check succeed or fail together.
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 alarms on consumer lag and DynamoDB throttling. |
| Data partitioning | Discusses using user_id as the DynamoDB partition key (DynamoDB already hashes it) to spread load, and what a very busy merchant wallet does to one partition. |
| 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 for its scaling and conditional transactional writes, and knows the catch with global tables in their default (eventually consistent) mode: concurrent writes in two regions resolve last-writer-wins and transactions are atomic only within one region, so each wallet's writes stay in one home region. |
| Global latency | Mentions DynamoDB Global Tables replicas for nearby balance reads (writes still go to the wallet's home region) 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.
- Caching without a staleness rule – a cached balance can lag behind the ledger; say it is for display only and that every debit checks the authoritative row.
- Forgetting operational concerns – no monitoring, no alerting, no backup plan.
- Mis-estimating scale – 100 k/day is only about 1.2 transactions a second, so the risk is building for a scale you do not have; size for today and say what changes at 10× and 100×.
Avoiding these pitfalls signals that you understand both the design and the real-world constraints of a financial service.
How to practice this
- Study a double-entry ledger, the core of a wallet: the worked design, Design a Double-Entry Ledger, is part of Pro ($10/month), and every component on it opens its notes.
- Draft your own design on paper or a whiteboard: start with the API layer, add async processing, then flesh out the data model and cache.
- Check your design against the junior, senior and staff sections above, looking for missing security checks, scaling assumptions, and operational gaps, then iterate. With Pro, the Coach can review your canvas against the ledger brief's rubric.
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, typically single-digit milliseconds, and still stay well 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?
Have the client create a unique idempotency key for each payment and resend the same key on retries. Store it as the transaction's primary key with a conditional write that fails if it exists, and make the debit conditional on the balance in the same transaction, so a retry is discarded and the wallet cannot go below zero.
What is the role of MSK in this design?
MSK decouples request ingestion from processing, provides replayability, and lets the consumer pool scale independently. Records the processor cannot handle can be sent to an SQS dead-letter queue.