Design a Card Payment Processing
Design a card payment processor: the service that online shops call to charge a customer's credit or debit card. A shopper types their card into the shop's checkout page; the shop asks us to authorize an amount; we ask the card network and the shopper's bank (the issuer) to approve it, and answer within a second or two. Later the shop captures the money, sometimes refunds it, and every night we settle with the networks and pay the shops out, minus our fee.
We serve 2 million merchants and 100 million payments a day, with holiday peaks of 10,000 authorizations a second. The hard parts are not the request rate. A payment must never be charged twice and never lost, even when the bank times out and the shop retries. Every cent must be accounted for in a ledger that balances, card numbers must never leak, and a slow bank or a broken network link must not take the rest of the system down.
Good questions to ask first
Decide what you would assume for each before you look at ours.
- 1Which payment flows?
- 2Do we talk to card networks directly?
- 3How fast must an authorization be?
- 4Do merchants send card numbers to us?
- 5What if the bank does not answer?
- 6How do merchants learn about changes?
- 7Which currencies?
- 8How much fraud checking?
How to spend the 45 minutes
- 5minPart 1: Requirements: flows, what exactly-once means
- 5minPart 2: Estimates, including money and in-flight auths
- 5minPart 3: API with idempotency keys
- 15minPart 4: Architecture, stage by stage
- 15minPart 5: Timeouts and reversals, ledger, PCI, settlement