For this week’s newsletter, we will cover:
How does VISA work when we swipe a credit card at a merchant’s shop?
What are the differences between bare metal, virtual machines, and containers? (YouTube Video)
How do you pay from your digital wallets, such as Paytm, Paypal, and Venmo, by scanning the QR code?
Flash sale system
System design exercise
How does VISA work when we swipe a credit card at a merchant’s shop?
VISA, Mastercard, and American Express act as card networks for clearing and settling funds. The card acquiring bank and the card issuing bank can be – and often are – different. If banks were to settle transactions one by one without an intermediary, each bank would have to settle the transactions with all the other banks. This is quite inefficient.
The diagram shows VISA’s role in the credit card payment process. There are two flows involved. Authorization flow happens when the customer swipes the credit card. Capture and settlement flow occurs when the merchant wants to get the money at the end of the day.
🔹Authorization Flow
Step 0: The card issuing bank issues credit cards to its customers.
Step 1: The cardholder wants to buy a product and swipes the credit card at the Point of Sale (POS) terminal in the merchant’s shop.
Step 2: The POS terminal sends the transaction to the acquiring bank, which has provided the POS terminal.
Steps 3 and 4: The acquiring bank sends the transaction to the card network, also called the card scheme. The card network sends the transaction to the issuing bank for approval.
Steps 4.1, 4.2, and 4.3: The issuing bank freezes the money if the transaction is approved. The approval or rejection is sent back to the acquirer, as well as the POS terminal.
🔹Capture and Settlement Flow
Steps 1 and 2: The merchant wants to collect the money at the end of the day, so they hit ”capture” on the POS terminal. The transactions are sent to the acquirer in batches. The acquirer sends the batch file with transactions to the card network.
Step 3: The card network performs clearing for the transactions collected from different acquirers, and sends the clearing files to different issuing banks.
Step 4: The issuing banks confirm the correctness of the clearing files, and transfer money to the relevant acquiring banks.
Step 5: The acquiring bank then transfers money to the merchant’s bank.
Step 4: The card network clears the transactions from different acquiring banks. Clearing is a process in which mutual offset transactions are netted, so the number of total transactions is reduced.
In the process, the card network takes on the burden of talking to each bank and receives service fees in return.
Over to you: Do you think this flow is way too complicated? What will be the future of payments in your opinion?
What are the differences between bare metal, virtual machines, and containers?
When deploying a modern application stack, how do we decide which one to use?
How do you pay from your digital wallets, such as Paytm, Paypal, and Venmo, by scanning the QR code?
To understand the process involved, we need to divide the “scan to pay” process into two sub-processes:
Merchant generates a QR code and displays it on the screen
Consumer scans the QR code and pays
Here are the steps for generating the QR code:
When you want to pay for your shopping, the cashier tallies up all the goods and calculates the total amount due, for example, $123.45. The checkout has an order ID of SN129803. The cashier clicks the “checkout” button.
The cashier’s computer sends the order ID and the amount to PSP.
The PSP saves this information to the database and generates a QR code URL.
PSP’s Payment Gateway service reads the QR code URL.
The payment gateway returns the QR code URL to the merchant’s computer.
The merchant’s computer sends the QR code URL (or image) to the checkout counter.
The checkout counter displays the QR code.
These 7 steps are completed in less than a second. Now it’s the consumer’s turn to pay from their digital wallet by scanning the QR code:
The consumer opens their digital wallet app to scan the QR code.
After confirming the amount is correct, the client clicks the “pay” button.
The digital wallet App notifies the PSP that the consumer has paid the given QR code.
The PSP payment gateway marks this QR code as paid and returns a success message to the consumer’s digital wallet App.
The PSP payment gateway notifies the merchant that the consumer has paid the given QR code.
Over to you: I have detailed how to pay using a dynamic QR code. It is dynamic because the QR code is dynamically generated each time. But sometimes, you could pay by scanning a printed QR code in a merchant’s shop, which is called the static QR code. Do you know how a static QR code works?
Flash sale system
Designing a system with extremely high concurrency, high availability, and quick responsiveness needs to consider many aspects 𝐚𝐥𝐥 𝐭𝐡𝐞 𝐰𝐚𝐲 𝐟𝐫𝐨𝐦 𝐟𝐫𝐨𝐧𝐭𝐞𝐧𝐝 𝐭𝐨 𝐛𝐚𝐜𝐤𝐞𝐧𝐝.
See the diagram below for details:
𝐃𝐞𝐬𝐢𝐠𝐧 𝐩𝐫𝐢𝐧𝐜𝐢𝐩𝐥𝐞𝐬:
Less is more. Fewer elements on the web page, fewer data queries to the database, fewer web requests, fewer system dependencies
Short critical path. Fewer hops among services or merge into one service
Async. Use message queues to handle high TPS
Isolation. Isolate static and dynamic contents, isolate processes and databases for rare items
Overselling is bad. When and how to manage the inventory is important
User experience is important. We don’t want to inform users that they have successfully placed orders but later tell them no items are available
System design exercise
Let’s try something different today.
Assuming in a system design interview, you are asked to design a distributed message queue. The following requirements are given:
Producers send messages to a message queue.
Consumers consume messages from a message queue.
Messages can be consumed repeatedly or only once.
The diagram below shows the naive design.
🔹Is the design correct?
🔹Do you think the design satisfies all the requirements?
🔹If not, what else should be added?
Feel free to make your assumptions, comment with anything you think might be helpful, or post your design.
Other things we made:
Our bestselling book “System Design Interview - An Insider’s Guide” is available in paperback and digital format.
Paperback edition: https://geni.us/XxCd
Digital edition: https://bit.ly/3lg41jK
New System Design YouTube channel: https://bit.ly/ByteByteGoVideos
Great content as always! Thanks a lot.
I'd like to add a thing or two about the settlement process with card networks. In step 4 of the Clearing and Settlement flow, networks such as Visa operate a bit differently in some regions.
For domestic transaction in Brazil, for example, the issuing banks have no direct contact at all with the acquiring banks.
Every day Visa sends the clearing files to the issuing banks, that must process and make the funds available. At the same time, it executes the settlement order through a clearing house.
In this process, Visa automatically calculates the fess and net values, then debits money from the issuers and credits the netted amount for the acquirers.
This is a special clearing operation only available for the card networks, regulated by the central bank and only available in a single clearing house.
I pray that we never stop receiving such great learning contents from you.