System-Design-Notes

[System Design] Payment system

flowchart LR
    a[Credit Card] -->|Pay-in| b[Platform's Bank Account] -->|Pay-out| c[Seller's Bank Account]

High-level Design

Untitled

Double-entry ledger system

To accurate bookkeeping.

Record every payment transaction into two separate ledger accounts with the same amount.

Untitled

Hosted payment page

Storing credit card info, companies need to deal with complex regulations.

Use hosted credit card pages provided by PSPs. For websites, it is a widget or an iframe, while for mobile applications, it may be a pre-built page from the payment SDK.

Untitled

Reconciliation

Untitled

Ensure correctness.

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.

May need the finance team to perform manual adjustments.

Handing payment processing delays

Situations where a payment request would stall:

Solution:

Untitled

Exactly-once delivery

At-least-once (Retry) + at-most-once.

Idempotency

Use a UUID as an idempotency key (usually the shopping cart ID).

If the payment system has already seen the key, return the latest status.