Here is what happens when you click the Buy button on Amazon or any of your favorite shopping websites.
1. When a user clicks the “Buy” button, a payment event is generated and sent to the payment service.
2. The payment service stores the payment event in the database. 1/6
3. Sometimes a single payment event may contain several payment orders. For example, you may select products from multiple sellers in a single checkout process. The payment service will call the payment executor for each payment order. 2/6
4. The payment executor stores the payment order in the database.
5. The payment executor calls an external PSP to finish the credit card payment. 3/6
6. After the payment executor has successfully executed the payment, the payment service will update the wallet to record how much money a given seller has.
7. The wallet server stores the updated balance information in the database. 4/6
8. After the wallet service has successfully updated the seller’s balance information, the payment service will call the ledger to update it.
9. The ledger service appends the new ledger information to the database. 5/6
10. Every night the PSP or banks send settlement files to their clients. The settlement file contains the balance of the bank account, together with all the transactions that took place on this bank account during the day. 6/6
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Here is a simplified design diagram that explains how a stock exchange such as Nasdaq or Newyork exchange works under the hood: #developers#systemdesign
Step 1: A client places an order via the broker’s web or mobile app.
Step 2: The broker sends the order to the exchange.1/6
Step 3: The exchange client gateway performs operations such as validation, rate limiting, authentication, normalization, etc., and sends the order to the order manager.
Step 4-5: The order manager performs risk checks based on rules set by the risk manager.2/6
Step 6: Once risk checks are passed, the order manager checks if there is enough money in the wallet.
Step 7 - 9: The order is sent to the matching engine. The matching engine sends back the execution result if a match is found. 3/6
One of the most serious problems a payment system can have is to 𝐝𝐨𝐮𝐛𝐥𝐞 𝐜𝐡𝐚𝐫𝐠𝐞 𝐚 𝐜𝐮𝐬𝐭𝐨𝐦𝐞𝐫. When we design the payment system, it is important to guarantee that the payment system executes a payment order exactly-once.1/6
At the first glance, exactly-once delivery seems very hard to tackle, but if we divide the problem into two parts, it is much easier to solve. An operation is executed exactly-once if:
1. It is executed at least once. 2. At the same time, it is executed at most once.2/6
We now explain how to implement at least once using retry and at most once using idempotency check.
𝐑𝐞𝐭𝐫𝐲
Occasionally, we need to retry a payment transaction due to network errors or timeout. Retry provides the at-least-once guarantee. 3/6