KatInterview

Architecting a Card Network Transaction Switch

System DesignModel answer
HardModel answerSystem Designpaymentsidempotencydistributed-transactions

Last updated

Design a card-network transaction switch that routes authorizations to unreliable issuer banks, prevents duplicate charges, keeps an auditable ledger, and keeps card data tokenized.

Build the Core of a Card Payment Network

You are designing the backend for a worldwide card network. It sits between merchants (via their acquirers) and issuing banks. The network does not hold cardholder funds. Issuers do. Your system routes requests, protects card data, records every transaction accurately, and tracks what each party owes for later settlement.

What the system must do

  1. Authorization: Ask the issuing bank whether the purchase can be approved against the cardholder's balance or credit limit.
  2. Capture: Complete the transfer of funds from the issuer's side to the merchant's side after a successful authorization.
  3. Safe retries: If a merchant retries a call because of a network failure, the cardholder must never be charged twice.
  4. Refunds and reversals: Support voiding, reversing, and refunding after the fact.

Quality targets

  1. Throughput and latency: Thousands of transactions per second, with a sub-second response for authorizations.
  2. Correctness under concurrency: Money must never be created, lost, or spent twice, even when requests race.
  3. Auditability: Every state change must be recorded for regulators and for reconciliation.

Constraints

  • Issuer APIs differ in speed and reliability, and some will be slow or down at times.
  • The design must satisfy PCI-DSS, so raw card numbers must be replaced by tokens and kept out of most of the system.

What to cover in your answer

  • The merchant-facing API.
  • A data model for transaction state, an audit trail, and ledger entries.
  • How the system talks to slow or failing external banks.
  • Your approach to idempotency and to consistency across services that cannot share a single database transaction.

State your scale assumptions and the trade-offs you make.

Hints

Hint 1

Begin by stating the numbers you assume (average and peak TPS, storage per day, latency budget), and decide which steps must be synchronous and which can run later.

Hint 2

Think of a payment as a state machine. Every change should be a conditional write in one local database transaction that also appends an audit event, a balanced ledger journal, and an outbox record.

Hint 3

You cannot run two-phase commit against a bank. Ask what you do when an issuer call times out and you do not know the outcome, and how compensating actions plus a retry-safe identifier can resolve it.

Hint 4

For idempotency, use a uniqueness constraint on (merchant, key) as the lock, store a hash of the request, and commit the stored response in the same transaction as the state change.