System Design Payment System: Interview Talk Track
"Design a payment system" is a favorite system design prompt because it forces you to think about correctness first. In many designs, losing an occasional update is acceptable. With money, charging a customer twice or losing a payment is not. Interviewers want to see that you understand idempotency, ledgers, external providers, and what happens when things fail halfway.
This system design payment system interview talk track gives you a structure for a 45-minute round. Adjust depth to your level and to where the interviewer steers.
1. Clarify requirements (about 5 minutes)
Functional requirements:
- A customer pays a merchant for an order (card or wallet).
- The system records each payment and its status: pending, succeeded, failed, refunded.
- Support refunds.
- Merchants receive payouts later.
- Users and merchants can view payment history.
Non-functional requirements:
- Correctness: no double charges, no lost payments.
- Reliability: high availability for accepting payments.
- Auditability: every money movement must be traceable.
- Scale: let's assume a few thousand payments per second at peak.
- Security and compliance: card data handled by a compliant payment provider; we avoid storing raw card numbers.
State the scope: "I'll focus on the pay-in flow with an external payment provider, the ledger, and reconciliation. Payouts I'll cover briefly."
2. High-level design (about 10 minutes)
Components:
- API / Payment service: receives payment requests from the checkout service.
- Payment database: stores payment records and their state.
- Payment provider (PSP): external service that actually charges the card.
- Ledger service: double-entry records of every money movement.
- Wallet / balance service: merchant balances derived from the ledger.
- Reconciliation job: compares our records with provider settlement reports.
- Message queue: for asynchronous events like "payment succeeded."
Flow for a payment:
- Checkout calls the payment service with an order ID, amount, currency, and an idempotency key.
- Payment service creates a payment record in
PENDINGstate. - It calls the PSP. The customer may be redirected for card authentication.
- The PSP responds or sends a webhook with the result.
- Payment service updates the record to
SUCCEEDEDorFAILED. - On success, the ledger records entries, and an event goes to the queue for order fulfillment and notifications.
3. Idempotency (the most important part)
Networks fail. Clients retry. Webhooks arrive twice. Without protection, a retry can charge twice.
- The client sends an idempotency key with each payment request, usually tied to the order.
- The payment service stores the key with a unique constraint. A repeat request with the same key returns the original result instead of creating a new charge.
- We pass our own idempotency key to the PSP, so even if our call to the provider is retried, the provider doesn't charge twice.
- Webhook handlers are idempotent too: processing "payment succeeded" twice must not create two ledger entries.
Say it plainly: "Every step that moves money must be safe to retry."
4. Ledger and data model (about 8 minutes)
Use double-entry bookkeeping: every transaction creates at least two entries that sum to zero.
| entry_id | txn_id | account | amount | currency | created_at |
|---|---|---|---|---|---|
| 1 | t1 | customer_payable | -100.00 | USD | ... |
| 2 | t1 | merchant_balance | +100.00 | USD | ... |
Key points:
- The ledger is append-only. Corrections are new entries (like a refund), never edits.
- Balances are derived by summing entries, often cached in a balance table updated in the same transaction.
- Store amounts as integers in the smallest currency unit (cents), never floating point.
- Payment records hold state; the ledger holds money movement. Keep them separate.
5. Consistency and failure handling (about 10 minutes)
Walk through the tricky cases:
- PSP call times out. We don't know if the charge happened. Keep the payment in
PENDING, then query the PSP using our idempotency key or wait for the webhook. Never blindly retry with a new key. - Our service crashes after the PSP charged. The webhook or a periodic status check will reveal the success; we then finish updating our records.
- Payment record updated but ledger write fails. Write both in one database transaction, or use the outbox pattern: write the state change and an outbox event together, then a worker publishes events reliably.
- Duplicate webhooks. Deduplicate by provider event ID.
Reconciliation: every day, compare our ledger and payment records with the provider's settlement files. Mismatches go to an alert queue for investigation. This is the safety net that catches anything the online flow missed.
6. Scaling (about 5 minutes)
- The payment service is stateless and scales horizontally.
- Partition payment and ledger data by merchant or account ID.
- Use a relational database with strong transactions for the ledger. Correctness beats raw write throughput here, and payment volumes are usually manageable per shard.
- Asynchronous consumers handle notifications, analytics, and fulfillment so they don't slow down the payment path.
- Read replicas or a separate store serve payment history queries.
7. Refunds and payouts (briefly)
- Refunds: a new transaction referencing the original payment, with its own idempotency key and reverse ledger entries.
- Payouts: a scheduled job aggregates merchant balances and sends transfers through the provider, recording ledger entries for each payout.
8. Wrap up
Summarize: "The core ideas are idempotency at every money-moving step, an append-only double-entry ledger, a state machine for payments, the outbox pattern for reliable events, and daily reconciliation as a safety net." Then offer deeper topics: fraud checks, multi-currency, or regional compliance.
Common mistakes
- Using floating-point numbers for amounts.
- Ignoring the "timeout, unknown outcome" case.
- Updating balances in place without an audit trail.
- Spending most of the time on load balancers instead of correctness.
Practice the talk track
Payment design questions reward calm, structured reasoning about failure. Luna Interview helps you rehearse system design talk tracks out loud with a timer, so you can walk through tricky failure cases clearly in the real round.
Run this structure end to end two or three times, and the important parts will come out naturally.
Rehearse with an AI interview copilot, then browse commonly reported interview questions.