Project 08
Payment processing
Idempotency, payment reliability
Brief
A payment service mediating between order systems and external providers: authorize, capture, refund; provider webhooks; retries; reconciliation; PCI-aware design.
Targets
500 payments/sec · never double-charge · 99.99% availability · every payment's state always determinable · provider failover under 1 minute.
Must cover
- Idempotent requests and unknown outcomes after timeouts (→ 38, 116).
- Reconciliation against provider settlement reports (→ 81).
- Compensation — refunds and releases as saga steps (→ 139).
- Authorization, capture, refunds and settlement as an explicit state machine (P).
- PCI DSS scope minimization through tokenization (P; → 171).
Design challenges
- Idempotency end to end (→ 38, 116): client keys → stored attempt records → provider keys; prove the double-click case and the timeout-retry case.
- The uncertain state: the provider call timed out — charged or not? A state machine
with
PENDING_UNKNOWNand the reconciliation job that resolves it (→ 126, 81). - Webhooks (→ 40): duplicated, reordered, delayed provider callbacks; signature verification.
- Provider abstraction with failover routing; circuit breaker per provider (→ 47 Strategy; → 151 — ahead, Part 9).
- The refund/cancellation flow as compensating transactions in the order saga (→ 139).
- Tokenization so card data never touches your servers — PCI scope minimization (→ 164, 171).
Out of scope
The ledger itself (Project 9); fraud scoring (integration point noted in step 21).