Architecting a Card Network Transaction Processing Engine
System DesignModel answerLast updated
Design a high-throughput, fault-tolerant card payment processing network that handles dual-phase payment processing, ledger auditing, and stand-in processing.
Design a global payment processing network (akin to Visa or Mastercard) that acts as the intermediary switch connecting acquiring banks (representing merchants) to issuing banks (representing cardholders).
Your system must handle the core end-to-end payment lifecycle across a globally distributed, highly available architecture.
Scope & Core Requirements
- Dual-Message Workflow:
- Authorization (Real-Time): Synchronous approval phase with tight latency constraints ($<500\text{ ms}$ $p99$).
- Clearing & Settlement (Asynchronous): Batch or stream-based multi-currency financial settlement and ledger updates at the end of the day/cycle.
- Resilience & Reliability:
- Idempotency & Reversals: Guaranteed exactly-once execution semantics for retries, dropouts, and explicit auto-reversals when downstream issuers time out.
- Stand-in Processing (STIP): Ability to evaluate rules and authorize/decline transactions on behalf of an issuer during network outages or timeout events.
- Ledger & Auditability:
- Immutable double-entry bookkeeping engine ensuring zero loss of transactional integrity across acquire/issue pairs.
- Data Privacy & Compliance:
- Compliance with PCI-DSS standards (tokenization/PAN isolation) and regional data sovereignty regulations.
Key Metrics to Target
- Throughput: 10,000 peak transactions per second (TPS), scalable to 50,000 TPS.
- Latency: $p99 \le 300\text{ ms}$ for authorizations.
- Availability: $99.999%$ (5 nines) uptime.
Hints
Hint 1
Distinguish clearly between the synchronous authorization path and the asynchronous clearing/settlement path.
Hint 2
Design an explicit state machine for transaction lifecycles to handle retries, network dropouts, and auto-reversals.
Hint 3
Use double-entry accounting principles for the settlement ledger to ensure financial consistency.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Scope & System Requirements
A payment network serves as a switch connecting Acquirers (merchant processors) to Issuers (cardholder banks).
[Merchant] ---> [Acquirer] ---> [Card Network Switch] ---> [Issuer Bank]
Functional Requirements
- Authorization (Real-Time Path): Validate transaction parameters, check balance/limits via the issuer, run fraud checks, and return an approval or decline code within a strict SLA.
- Clearing & Settlement (Async Path): Batched or event-driven financial reconciliation where money actually moves from issuing accounts to acquiring accounts.
- Stand-In Processing (STIP): Evaluate risk models and approve/decline on behalf of unreachable issuers.
- Idempotency & Reversals: Handle network drops gracefully using idempotency keys and automatic windowed reversals.
- Ledgering: Immutable, double-entry financial ledger recording all debit/credit legs.
Non-Functional Requirements
- Throughput: 10,000 steady-state TPS; 50,000 peak TPS.
- Latency: $<300\text{ ms}$ $p99$ end-to-end for authorization.
- Availability: $99.999%$ annual availability ($<5.26$ minutes downtime/year).
- Security & Compliance: PCI-DSS compliance via Tokenization Vaults; regional data sovereignty.
2. High-Level Architecture
The architecture decouples the low-latency Authorization Path from the asynchronous Clearing & Settlement Pipeline.
+-----------------------------------+
| PCI-DSS Vault Domain |
| (PAN <-> Tokenization Engine) |
+-----------------+-----------------+
|
[ Tokenized Payload ]
|
+----------+ +-------------------+ v +-----------------------+ +---------------+
| Acquirer | ---> | API Gateway / ELB | ----------> | Authorization Service | ---> | Routing Engine|
+----------+ +-------------------+ +-----------+-----------+ +-------+-------+
| |
+---------+---------+ |
| Outbox / Event Bus| v
+---------+---------+ +------------------+
| | Issuer / STIP |
v | Decision Engine |
+-------------------+ +------------------+
| Settlement Engine |
+-------------------+
3. Deep Dive into Core Subsystems
A. Real-Time Authorization Path & State Machine
- Ingress: The Acquirer submits an ISO 8583 / ISO 20022 formatted message containing transaction details.
- Tokenization: Primary Account Numbers (PANs) are swapped for internal tokens at the edge proxy, isolating sensitive data to a dedicated, highly restricted PCI-DSS Vault.
- State Machine Initialization: An idempotent transaction state is initialized in a high-speed distributed cache (e.g., Redis Cluster across multiple availability zones).
+-----------+ Timeout / Fail +-----------------------+
| PENDING | -----------------------> | REVERSED / STIP_DECL |
+-----+-----+ +-----------------------+
|
| Issuer Approved
v
+-----------+ Batch File +-----------------------+
| AUTHORIZED| -----------------------> | CLEARED & SETTLED |
+-----------+ +-----------------------+
- Issuer Routing & Circuit Breaking:
- The Routing Engine directs the request to the cardholder's issuing bank via pre-established persistent MTLS tunnels.
- If the Issuer connection fails or times out ($>150\text{ ms}$ threshold), a Circuit Breaker trips, handing control off to the STIP Engine.
- STIP uses velocity rules, cached card balance limits, and ML models to render a decision on the issuer's behalf.
B. Idempotency & Auto-Reversal Mechanism
In real-time financial switches, network timeouts create ambivalence: did the issuer approve and fail to answer, or did the request never arrive?
- Deduplication Key: Generated using
Hash(Acquirer_ID + Merchant_ID + Retrieval_Reference_Number + Amount + Currency). - Timeout Handling:
- If the network switch times out waiting for the issuer, an Auto-Reversal (0400 message) is dispatched asynchronously to the issuer to cancel any held funds.
- A
DECLINED_TIMEOUTresponse is returned to the acquirer. - If an authorization response arrives after the client timeout, the switch catches the late arrival via the idempotency key and generates an immediate compensation credit.
C. Clearing, Settlement, and Double-Entry Ledger
Authorization merely places a hold on funds; Clearing transfers the transaction records, and Settlement moves actual money across central bank accounts.
- Transaction Event Log: Upon authorization completion, an immutable record is published to a partitioned, replicated log (e.g., Apache Kafka with
acks=all). - Clearing Pipeline:
- At end-of-day (or in micro-batches), transactions are aggregated per Acquirer-Issuer pair.
- Net positions are calculated: $\text{Net Position} = \sum \text{Debits} - \sum \text{Credits}$.
- Immutable Double-Entry Ledger:
- Every movement of money must balance: $\sum \text{Debits} = \sum \text{Credits}$.
-- Conceptual Schema for Ledger Entry
CREATE TABLE ledger_entries (
entry_id UUID PRIMARY KEY,
transaction_id UUID NOT NULL,
account_id UUID NOT NULL, -- Belongs to Acquirer, Issuer, or Network Fee Account
entry_type VARCHAR(10) CHECK (entry_type IN ('DEBIT', 'CREDIT')),
amount DECIMAL(18, 4) NOT NULL,
currency VARCHAR(3) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
4. Data Storage Strategy
| Component | Storage Engine | Reason |
|---|---|---|
| Auth Session & State | Redis (Multi-AZ Cluster) | Sub-millisecond latency for idempotency keys & state locks. |
| Immutable Event Log | Apache Kafka / EventStore | Order-preserved append-only storage for audit trails. |
| Clearing Ledger | Distributed SQL (CockroachDB / AWS Aurora) | ACID transactions, strict serializability, horizontal scale. |
| Token Vault | Key-Value Store with KMS Hardware | Enforced zero-trust access for PAN tokenization. |
5. Failure Modes & Mitigations
- Issuer Unreachability:
- Mitigation: Fall back to STIP within $150\text{ ms}$. Log all STIP decisions for post-outage reconciliation with the issuer.
- Network Partition (Split-Brain):
- Mitigation: Multi-region database deployments use a consensus protocol (Raft/Paxos). The authorization cache relies on strict regional ownership determined by the issuing bin route.
- Duplicate Requests (Retries):
- Mitigation: Enforce distributed locking via Redis (
SETNX) on the idempotency key during request execution. Return cached result if key exists.
- Mitigation: Enforce distributed locking via Redis (
6. Summary of Architectural Trade-offs
- Consistency vs. Availability in Auth Path: Optimized for High Availability via STIP fallback. If an issuer is unavailable, we prioritize transaction continuity over strict issuer-side real-time balance validation.
- Synchronous Authorization vs. Asynchronous Settlement: Synchronous execution is restricted to what is necessary for validation ($<300\text{ ms}$). Detailed ledger posting and cross-border currency conversions are deferred to the asynchronous settlement pipeline.