Receive Notifications
Validate events
Process Events
Store Events
Notification Service
The system should have high consistency
Suppose we have 1M DAU who makes 1 transactions per day.
{
"event": "payment.success",
"data": {
"transaction_id": "123456789",
"amount": 100.00,
"currency": "USD",
"customer_name": "John Doe",
"status": "success",
"timestamp": "2022-01-01T12:00:00Z"
"authentication": xxxx
}
}
Transaction
transaciton_id
user_id
status
last_update_timestamp
authentication_token:
amount
order_id
Order
order_id
item [list]
Payment Service: External service which handles payment
Validation Service: This is to make sure that the callback is being executed by Payment Service instead of any scam service providers.
Message Queue: In case where process service could not handle large amount of payment callbacks, we will add a message queue. The validation service will validate the call back first and if it passes validation, it will reformat the content into input for Process Service.
Process Service: this is the backend service to process the order The order should be persist into database.
Database, stores
When a customer created an order and decide to make a payment, the order processing service will create an order with payment pending status. Then it sends the input to the Payment Service for payment. The user will need to perform some operations in the payment service. Once that process is done, either the payment is successful or failed, the payment service will send info back to validation service. If the payment has timed out, the Payment service should return failed. Order Processing Svc will also send the order information to Order Monitoring Svc because it needs to monitor active orders whether the payment has been successful. If the payment is timed out, it will mark the order to failed state in the database
In order processing service, it will first create a new entry in the database (new order_id). Next, it will generate clientToken and secret as body and send to Payment (usually 3rd party) for payment. It will also send the order to order monitoring svc. If payment times out, the order monitoring svc will set the order in the database to failed and close the order.
The backend server will be listening to the payment service to call back.
Callback vs webhooks. Webhooks are async and cross environment. When dependent on 3rd party payment systems, it needs to be webhook.
Network errors
Timeouts
Invalid requests
Authentication failures
Payload Errors
Throttling errors
Notification Delivery Failures
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?