Step 1: Requirements and estimates
Start by asking what the payment system must do and what must never happen.
Functional requirements:
- Customers pay for orders with cards and wallets (Apple Pay, Google Pay), including extra verification like 3-D Secure.
- The shop can refund all or part of a payment.
- The shop pays out to sellers (if it’s a marketplace), minus its fees.
- Finance gets reports that match what the provider and the bank say.
What must never happen:
- Charging a customer twice for one order.
- Losing track of a payment: money taken but no order, or an order marked paid without money.
- Card numbers stored on the shop’s servers.
The volumes are small compared with other systems, so the design focuses on correctness and auditability, not speed.
Clarify: payment methods and regions (cards, wallets, bank transfers, SCA/3-D Secure in Europe), authorization vs capture (capture on shipment?), partial refunds and partial captures, marketplace splits and payouts, currencies (store amounts as integer minor units with an explicit currency, never floats), and reporting needs. Non-functional: exactly-once effect per order attempt, durability of every money movement, an append-only audit trail, reconciliation with the provider’s settlement reports, and PCI DSS scope minimization through provider tokenization (hosted fields, SDKs) so raw card data never touches your servers. Throughput is modest; availability matters at checkout, but correctness wins every trade-off: a delayed confirmation is acceptable, a double charge isn’t.
Orders: 1 million / day → ~12 payments / s average, ~100 / s peak (sales)
Payment API calls: ~3 per payment (create, confirm, webhook) → a few hundred / s at peak
Ledger entries: ~4 per payment (charge, fee, payout, refunds) → ~4 million rows / day
Storage: ~1 KB per entry with metadata → ~4 GB / day, kept 7–10 years (audit, tax)
Throughput is easy. The hard requirements are:
- exactly-once effect per order, despite retries and timeouts
- every cent traceable from order → payment → ledger → provider report → bank- 12 payments per second is nothing for a database. A single well-indexed PostgreSQL instance handles it.
- The ledger grows forever and is kept for years, because accountants and tax authorities need it.
- So the questions in the next steps are about what can go wrong, not about scaling.
- Methods, regions, SCA/3-D Secure, authorize vs capture, partial refunds/captures, marketplace payouts, multi-currency (integer minor units + currency code).
- Exactly-once effect per order attempt, append-only audit trail, reconciliation with provider settlements, PCI scope minimized via tokenization.
- Low throughput (tens to hundreds per second); correctness beats latency; “unknown” is a real state after timeouts.
Check this part
What is the hardest requirement in a payment system?
Why should card numbers never reach the shop's servers?
How should amounts be stored?