Design of a Payment System
Define the System Design for a secure payment processor, covering high-level architecture, APIs, and storage schema. Detail components like fraud detection and reconciliation. Learn to ensure transaction reliability and resilience by applying idempotency, retry strategies, and fallbacks to manage transient failures.
We'll cover the following...
In the previous lesson, we defined the requirements and resource estimates for our payment system. Now, we will cover its high-level design.
High-level design
A customer clicks the pay button on a merchant’s website, which triggers the payment service.
The payment service processes the customer’s information and sends the transaction details to the risk check system for fraud detection.
If the transaction passes the risk check, the payment service forwards the request to the payment gateway.
The payment gateway validates the payment details and forwards the request to the card issuer’s bank.
The issuer’s bank processes the request and sends the payment to the merchant’s account via the payment service.
The merchant’s account balance is updated to reflect the successful transaction.
Now that we have a high-level design, let’s define the APIs that will serve as the system’s entry points.
API design
The following APIs are essential to meet our functional requirements.
User registration and authentication
User registration: This API handles new user registration.
registerUser(username, email, password)
The registerUser API hashes the user’s password before saving it to the database. The table below explains the API’s parameters.
Parameter | Description |
| A unique user name opted for by the customer. |
| Customer’s email id to be used later in the authentication phase. |
| The customer’s password is used for authentication later. |
User authentication: This API authenticates users. We will assume a basic authentication mechanism.
authenticateUser(username, password)
Payment processing
The following APIs handle payment processing tasks.
Payment authorization: This API verifies that the customer has sufficient funds to complete the payment. If successful, it associates the transaction with the merchant and returns an authorization code.
authorizePayment(amount, card_number, expiration_date, CVV, merchant_id)
The table below describes the API’s parameters.
Parameter | Description |
| The amount to be paid by the customer for a purchase. |
| 16-digit customer’s payment card number. |
| The expiry date of the payment card. |
| A 3-digit card verification value of the payment card. |
| A unique identifier for the merchant receiving the payment. Used to route the transaction and reserve funds for the correct merchant account. |
Payment capture: This API captures previously authorized ...