Design the ledger and payments service for Tallowmere Market, an online marketplace with built-in wallets. Buyers pay sellers, the marketplace takes a fee on every sale, buyers can be refunded, and sellers withdraw their balance to a bank account. Card charges and bank payouts go through an external payment processor.
Requirements: every movement of money is recorded as double-entry and never edited; a payment happens exactly once even when the mobile app retries after a timeout; a seller's wallet can never go negative; and the ledger is reconciled daily against the processor's settlement file.
Rough scale to start from: 3,000 payments per second at peak, 20 million wallets, about 400 million ledger entries per month, and balance reads under 50 ms at p99. For writes, correctness matters more than availability.
Cover:
- The data model for accounts, transactions and entries, and how balances are read.
- Idempotency keys: where they are stored, their scope, and what a retry returns.
- Calls to the external processor that can fail or time out, and keeping the ledger and the processor consistent.
- Hot accounts, reconciliation and auditing.
Start by clarifying requirements, then work through the design end to end.