Whiteboard ScaleTopicsPayment Processing

Credit Card Processing System

COMMON

Credit card processing is asked at every fintech and major tech company because it tests exactly-once guarantees, distributed state machines, and financial data integrity. It is how Stripe processes 250M API requests per day across millions of merchants. You will design a payment gateway handling 10K transactions per second where a network timeout mid-charge must never result in a double charge or lost payment, using idempotency keys, a 5-state payment machine, and a double-entry ledger.

  • Guarantee exactly-once payment processing with idempotency keys
  • Design a 5-state payment machine that prevents double charges
  • Build a double-entry ledger where every cent is accounted twice
StripeSquarePayPalAmazonGoogleAdyen
8
Concepts
Deep dives
10
Cheat Items
Quick ref
Elevator Pitch3-minute interview summary

I would design a credit card processing system for 50M merchants handling 10K TPS at peak. Each transaction flows through a 5-state machine with an idempotency key enforced by a PostgreSQL UNIQUE constraint for exactly-once processing. Per-transaction storage is 900 bytes across 432M daily transactions, totaling 389 GB/day. A double-entry ledger records every state change. Card network calls use 2-second timeouts with T+1 reconciliation for ambiguous responses. Webhooks retry via exponential backoff and a dead letter queue. 99.99% availability, zero double charges.

Concepts Unlocked8 concepts in this topic

Idempotency Keys

STANDARD

PostgreSQL UNIQUE constraint on (merchant_id, idempotency_key) in one ACID transaction. Makes double-insert physically impossible. 2ms overhead per request.

Core Feature Design

Payment State Machine

STANDARD

5 states (pending, authorized, captured, settled, failed) with forward-only transitions. Each change logged in append-only ledger. 7-day capture window.

Core Feature Design

Tokenization (PCI-DSS)

EASY

Raw PANs replaced with tokens at the edge. Dedicated token vault in isolated VPC. Reduces PCI audit scope from hundreds of servers to one vault.

High Level Design

Two-Phase Capture

STANDARD

Authorize (hold) then capture (move money) within 7 days. Hotels, e-commerce, restaurants. Partial capture allowed. Avoids refund delays.

Core Feature Design

Double-Entry Ledger

TRICKY

Every txn creates 2 entries: debit + credit. Append-only, no UPDATE/DELETE. 864M rows/day. Refunds are new entries, not reversals. Sum debits = sum credits always.

Database Schema

Webhook Delivery with Retry

STANDARD

1.3B webhooks/day via Kafka. Exponential backoff (1m, 5m, 30m, 2h, 24h). DLQ after 5 retries. HMAC-SHA256 signature. At-least-once delivery.

Replication and Fault Tolerance

Card Network Routing

EASY

Merchant -> acquirer -> card network (Visa/MC) -> issuing bank. 2-second timeout. On timeout: mark unknown, reconcile T+1. Never retry a timed-out charge.

High Level Design

Reconciliation & Settlement

TRICKY

T+1 settlement file from card network. Line-by-line comparison against ledger. 389 GB/run across 50 workers. Settlement at T+2/T+3. Zero-delta target.

Replication and Fault Tolerance