How would you design a ledger for a wallet or payments product so balances are always correct?
What the interviewer wants to hear
- Double-entry bookkeeping: every transfer has balanced debit and credit entries
- Entries are immutable and append-only; corrections are new entries
- Integer minor units with currency, never floats
- Idempotency keys and strong transactions or row locking to avoid double spends
- Balances derived from entries, cached with checks, and reconciled with providers
Model answer
I would use double-entry bookkeeping. Every movement of money is a journal transaction with two or more entries, debits and credits, that must sum to zero, so money is never created or lost by a bug. Entries are append-only and never updated; a mistake is fixed with a reversing entry, which gives a full audit trail. Amounts are stored as integers in minor units, like cents, together with a currency code. Each request carries an idempotency key with a unique constraint so retries do not double charge. To stop overspending, I write the entries and update a cached balance in one database transaction, locking the account row or using a version check, and enforcing that the balance cannot go below zero. The cached balance can always be rebuilt from entries. Daily reconciliation compares the ledger with bank and provider reports.
Can you answer it under time pressure?
Take a timed hard round and get scored on every answer.
More hard Backend Developer questions
- Design a URL shortener like bit.ly that handles 100 million new links per month and many more redirects. Cover IDs, storage, caching and scale.
- A product manager says each payment event must be processed exactly once. How do you achieve that with real message queues and networks?
- Your single PostgreSQL database is reaching its limits. How would you scale reads and then writes, and what problems does each step bring?
- In a microservices system, placing an order touches the Order, Payment and Inventory services, each with its own database. How do you keep data consistent?
- You are building a B2B SaaS backend used by many companies. How would you design multi-tenancy and make sure one tenant can never see another tenant data?
- Design a notification service that sends email, SMS and push messages for many products, up to tens of millions of messages a day.
- Your company wants to split a large monolith into microservices. How would you approach it, and when would you argue against it?
- Design the backend for a real-time chat app with one-to-one and group chats, online status and message history.
- One slow downstream dependency caused your whole platform to go down. How would you handle the incident, and what would you change afterwards?