45. Design a Payment System (Stripe / UPI)
1
The interview prompt2
45.1 What do you ask first?3
45.2 How big is this, really?4
45.3 What are the doors?5
45.4 What do we store?6
45.5 What does the whole system look like?7
45.6 How does idempotency work end to end?8
45.7 How does a double-entry ledger work?9
45.8 How does reconciliation work?10
45.9 How do callbacks and webhooks work?11
45.10 How do you keep it consistent?12
45.11 What would you say in the last five minutes?13
Score yourself14
Variations to practise15
Sources16
Code lab45. Design a Payment System (Stripe / UPI)
45.1 What do you ask first?
3 min read+10 XP
Step 1: Requirements (5 minutes)
| Letter | Candidate asks | Interviewer answers |
|---|---|---|
| Scope | "Accept payments, refunds, payouts to merchants? Which methods? Do we store card numbers? Subscriptions?" | "Payments and refunds by card and UPI, and a record of merchant balances for payouts. Card data goes to a certified vault; we keep tokens. Skip subscriptions." |
| Count | "How many payments?" | "Up to about 2,000 payments a second at peak; tens of millions a day." |
| Access pattern | "How do results come back?" | "Sometimes immediately, often seconds or minutes later by callback; sometimes never, and we must find out." |
| Latency | "How fast must a payment complete?" | "A few seconds for the customer; callbacks can be later." |
| Exactness | "Can we lose or double-charge a payment? Can balances be approximate?" | "Never. Every paisa must be accounted for and auditable." |
Agreed requirements:
- Functional (verbs): merchants create payments; customers pay by card or UPI; the system captures, refunds, records merchant balances, notifies merchants (webhooks), and reconciles with banks.
- Non-functional (adjectives): exactly-once effect (no double charges), never lose a payment, correct and auditable money records, highly available, secure (no raw card data in our systems, signed callbacks), resilient to slow and silent banks.
Interviewer pushback:
- "Why not just store a balance column per merchant and update it?" → Because a single number can't be audited: when it's wrong, you can't tell why. A ledger of balanced entries explains every change, and the balance is derived from it (45.7).
Memory code: "Ask how money moves, how results come back, and how you'll prove it later."