Design a Payment System
Understanding the Problem
💳 What is a payment system? A payment system lets a business take money from a customer and get it into the business's bank account. A payment service provider (PSP) like Stripe, Adyen or Braintree sits between merchants and the banking world: the merchant sends "charge this card $42," and the PSP talks to the banks and card networks, tracks the payment through its lifecycle and tells the merchant what happened. The hard part isn't speed. It's never charging twice, never losing a charge, and knowing the true state of a payment when a bank stops answering.
You'll get this question in two shapes. One is "design Stripe": you are the PSP, and merchants call your API. The other is "design the payment system for our e-commerce site," where you sit on the merchant side and may call several PSPs, routing each payment to the best one (a payment aggregator or orchestration layer). They're the same problem from two vantage points. The core state machine, idempotency and reconciliation are identical; the difference is what sits on the far side of your connector. We'll design the PSP and cover multi-PSP routing in a deep dive.
How a Card Payment Actually Moves
It's worth a minute on the card ecosystem, because the design follows from it, and interviewers like candidates who know who the parties are.
- The cardholder has a card issued by an issuing bank (Chase, Barclays). The issuer holds the account and decides whether to approve each charge.
- The merchant has an account with an acquiring bank (the acquirer), which accepts card payments on the merchant's behalf. A PSP either is an acquirer or works with one.
- The card network (Visa, Mastercard) connects acquirers to issuers, routes messages between them, sets the rules and runs clearing and settlement. This is the four-party model. American Express and Discover historically act as both network and issuer (a three-party model).
A card payment happens in two phases:
- Authorization (real time, around 1-2 seconds). The acquirer sends an authorization request through the network to the issuer. The issuer checks the balance or credit limit and fraud signals, and replies approve or decline. If approved, it places a hold on the funds. No money has moved yet.
- Clearing and settlement (batch, usually daily). The merchant captures the authorized amount (immediately for digital goods, at shipping time for physical ones). Captures go to the network in a clearing file, the network nets out what every issuer owes every acquirer, and money moves between banks, typically a day or two later. The acquirer then pays the merchant, minus fees.
Fees come out along the way: interchange goes to the issuer, scheme fees to the network, and the acquirer or PSP adds its own margin. Later, a cardholder can dispute a charge with their issuer, which starts a chargeback that pulls the money back from the merchant unless they win the dispute.
Two other pieces come up a lot. 3-D Secure (3DS) is an extra step where the issuer authenticates the cardholder (a bank app prompt or one-time code), required for many payments in Europe under Strong Customer Authentication rules. And PCI DSS is the security standard for anyone who stores, processes or transmits card numbers. Its scope drives a big piece of the architecture.
Functional Requirements
We'll pin the scope down with our interviewer. A real PSP has hundreds of features, so we focus on the payment lifecycle.
Core Requirements
- Merchants should be able to charge a customer's card: create a payment and have it authorized.
- Merchants should be able to capture, cancel and refund a payment.
- Merchants should be able to find out the outcome of every payment, both by querying it and by receiving webhooks.
Below the line (out of scope)
- Other payment methods (bank debits, wallets, buy now pay later). They plug into the same lifecycle with a different connector.
- Merchant onboarding, identity verification (KYC) and risk underwriting.
- The full fraud model. We'll leave a hook for a risk score; see /system-design/fraud-detection.
- Dispute handling workflows beyond recording that a chargeback happened.
Non-Functional Requirements
Ask your interviewer for scale, but expect the answer to matter less than in most questions. Let's say 100 million payments a day across all merchants, with peaks (Black Friday, a big merchant's launch) around 10x the average.
Core Requirements
- The system must never charge a customer twice for the same payment, and never lose track of a charge the bank accepted. Correctness beats availability for the money path.
- The system should be highly available (99.99%+ for payment creation and authorization). An outage means merchants lose sales.
- Authorization should add little latency on top of the bank's: our overhead under ~200 ms, with total time dominated by the issuer's 1-2 seconds.
- The system must keep card data secure and keep as few components as possible in PCI scope.
- Every money movement must be auditable and reconcilable against bank and network reports.
Below the line (out of scope)
- Multi-currency FX pricing and cross-border tax.
- Running our own connection to the card networks from scratch. We'll assume we connect through acquirers or processors.
Back of the envelope: 100M payments/day is about 1,160 per second on average, call it 12k/s at peak. Each payment produces maybe 5-10 state changes over its life (created, authorized, captured, refunded, settled, plus webhook deliveries), so the write load is on the order of 100k small writes per second at peak. That's real, but it's well within a sharded relational database. Storage: at ~10 KB per payment including its attempts and events, around 1 TB a day, a few hundred terabytes over several years, which we'll have to keep for audit.
The more interesting number is in-flight state. At 12k/s with 2 seconds per authorization, about 24,000 authorizations are waiting on banks at any moment. Each one is a remote call that can time out, and any timeout leaves us not knowing whether the customer was charged.
Payment systems are not hard because of QPS. They're hard because every call to the outside world can succeed, fail, or neither (you don't know). Make that third outcome the centerpiece of your design and your interviewer will notice.