Let us assume we have to handle 10 Million transactions per day. To calculate the transactions per second, we'll divide the total number of transactions per day by the number of seconds in a day.
Total transactions per day = 10,000,000
Number of seconds in a day = 86,400
Transactions per second = Total transactions per day / Number of seconds in a day
Transactions per second = 10,000,000 / 86,400
Transactions per second ≈ 115.74 transactions per second
So, the system needs to process approximately 115.74 transactions per second.
Given that 1 server can handle 1000 concurrent requests, we'll need to calculate the number of servers required to handle the total load.
However, for high availability scenarios, we need to consider redundancy and failover. Let's assume a redundancy factor of 2 for high availability.
We can roughly estimate 200 servers will be required to support our scale.
If each transaction contains 100 KB of data, we can calculate the total data generated per year and then estimate the storage required for 5 years.
Data per transaction = 100 KB
Total transactions per year = 10,000,000 * 365 ≈ 3,650,000,000
Total data generated per year = Data per transaction * Total transactions per year
Total data generated per year = 100 KB * 3,650,000,000 ≈ 365,000,000,000 KB
Total data generated for 5 years = Total data generated per year * 5
Total data generated for 5 years ≈ 365,000,000,000 KB * 5
Total data generated for 5 years ≈ 1,825,000,000,000 KB
Total data generated for 5 years ≈ 1.825 petabytes (PB)
So, approximately 1.825 petabytes of storage will be required for 5 years.
Performance Requirements:
For designing payment systems, multiple APIs will be required, below is a list of few essential APIs.
For the tables required in this design, refer to the class diagram, the list of classes is not exhaustive but this is a good number of tables to start with.
For the given problem of designing an online payment system, the best partitioning strategy would likely involve a combination of regional or geographical partitioning and functional partitioning.
Partitioning Algorithm:
When it comes to implementing partitioning for the system, a common algorithm used is consistent hashing.
Horizontal scaling would be the best strategy for scaling the databases in this scenario. It allows for adding more servers to the existing infrastructure, enabling better performance and higher availability without significant changes to the application architecture. With the growing user base and transaction volume, horizontal scaling ensures seamless expansion by distributing the workload across multiple nodes.
Implementing Read/Write Separation could be beneficial to optimize the system's performance and scalability. By directing read operations to read replicas or caches, the system can handle a larger volume of read requests without impacting write operations. This separation improves overall system responsiveness and user experience, especially during peak usage periods.
Below is a simple sequence diagram for Payment flow.
Before jumping into the detailed design, let's first understand a few components and their roles.
Now let's discuss the detailed component design
Payment Executor:
The double-entry system states that the sum of all the transaction entries must be 0. One cent lost means someone else gains a cent. It provides end-to-end traceability and ensures consistency throughout the payment cycle. Double-entry system is fundamental to any payment system and is key to accurate bookkeeping. It records every payment transaction into two separate ledger accounts with the same amount.
Overview:
Application in Payment Systems:
Reconciliation
In an asynchronous communication environment, where messages may not be delivered or responses returned, ensuring correctness becomes crucial. Reconciliation serves as a practice to periodically compare states among related services, verifying their agreement, and acting as the last line of defense in payment systems. Every night the PSP or banks send a settlement file 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. The reconciliation system parses the settlement file and compares the details with the ledger system. Reconciliation is also used to verify that the payment system is internally consistent. For example, the states in the ledger and wallet might diverge and we could use the reconciliation system to detect any discrepancy.
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?