In a payment system, itโs very important to separate ๐ข๐ง๐๐จ๐ซ๐ฆ๐๐ญ๐ข๐จ๐ง ๐๐ฅ๐จ๐ฐ ๐๐ง๐ ๐๐ฎ๐ง๐ ๐๐ฅ๐จ๐ฐ.1/6
In the diagram below, we have three layers:
- Transaction layer: where the online purchases happen
- Payment and clearing layer: where the payment instructions and transaction netting happen
- Settlement layer: where the actual money movement happen 2/6
The first two layers are called information flow, and the settlement layer is called fund flow. 3/6
You can see the information flow and fund flow are separated. In the info flow, the money seems to be deducted from one bank account and added to another bank account, but the actual money movement happens in the settlement bank at the end of the day. 4/6
Because of the asynchronous nature of the info flow and the fund flow, reconciliation is very important for data consistency in the systems along with the flow. 5/6
It makes things even more interesting when Bob wants to buy a book in the Indian market, where Bob pays USD but the seller can only receive INR. 6/6
โข โข โข
Missing some Tweet in this thread? You can try to
force a refresh
Metrics collection is a popular system design interview question. There are two ways metrics data can be collected, pull or push. It is a routine debate. In this post, we will take a look at the pull model. 1/8
Figure 1 shows data collection with a pull model over HTTP. We have dedicated metric collectors which pull metrics values from the running applications periodically. 2/8
In this approach, the metrics collector needs to know the complete list of service endpoints to pull data from. One naive approach is to use a file to hold DNS/IP information for every service endpoint on the โmetric collectorโ servers. 3/8
One picture is worth more than a thousand words. This is what happens when you buy a product using Paypal/bank card under the hood.1/8
To understand this, we need to digest two concepts: ๐๐ฅ๐๐๐ซ๐ข๐ง๐ & ๐ฌ๐๐ญ๐ญ๐ฅ๐๐ฆ๐๐ง๐ญ. Clearing is a process that calculates who should pay whom with how much money; while settlement is a process where real money moves between reserves in the settlement bank. 2/8
Letโs say Bob wants to buy an SDI book from Claireโs shop on Amazon.
- Pay-in flow (Bob pays Amazon money): 1.1 Bob buys a book on Amazon using Paypal. 1.2 Amazon issues a money transfer request to Paypal.3/8
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
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