Courses / System Design Interview / Chapter 40
Module 9 · Design Problems IV: Platforms and Money · Chapter 40 of 49
Design a Payment System
Builds on Core Concepts: RPCs, Consistency, Failures and Time, Back-of-the-Envelope Estimates, Databases: Choosing, Replicating and Partitioning, Distributed Message Queues and Distributed Task Schedulers. Next up: Design an Online Judge like LeetCode.
Part 1 · Requirements and who holds what
Who is involved
A payment system lets a shop charge a customer and know, for certain, whether the money moved. It is a small problem to describe and an unforgiving one to build, because the usual failures of distributed systems, a timeout, a retry or a crash, can mean a customer is charged twice or not at all.
Four parties appear in every design. The customer pays from a bank account, a card or a wallet. The merchant is the business selling something, and its system is the one we design. A payment service provider, or PSP, is a company the merchant integrates with that talks to banks and card networks on its behalf and exposes one API for several payment methods, such as UPI and cards. The banks and networks behind the provider hold the customer's money and make the actual transfer. We design the merchant's payment service and its dealings with the provider. We do not design the provider or the banking network.
The split decides what each side holds. The provider holds the sensitive payment details, such as a card number, and the real record of the transfer. The merchant holds an order, a payment record with an amount and a status, the provider's reference for the transaction, and its own books of what is owed. The PCI Security Standards Council describes its data security standard as requirements to protect environments where payment account data is stored, processed or transmitted. Our design choice is to keep card numbers out of our systems altogether, by having the customer enter them into a form that the provider hosts, so that our servers only ever see a token and a status. That is meant to narrow the part of our systems that such requirements apply to.