Design a scalable payment system
Company: OpenAI
Role: Software Engineer
Category: System Design
Difficulty: hard
Interview Round: Technical Screen
##### Question
Design a scalable payment system. The system must support both peer-to-peer money movement between users and merchant payments (accepting card and digital-wallet payments), with refunds, chargebacks, and full transaction history. Assume it may integrate with external payment rails/providers (card networks, bank transfers).
Cover the following:
1. **Core product requirements:** user-to-user (wallet-to-wallet) transfers, merchant card/digital-wallet payments, refunds, chargebacks/disputes, payment status tracking, and per-user/merchant transaction history.
2. **API design:** key endpoints (authorize, capture, refund, void, create-payment, get-payment), request/response fields, idempotency keys, and exactly-once charge semantics (no double-spend).
3. **Money-movement model:** a double-entry ledger; authorization vs capture, holds/reservations, settlement, and reconciliation; how you represent accounts, balances, and transactions.
4. **End-to-end flow & PCI scope:** the flow across gateway, acquirer, card networks, and issuers; tokenization and the PCI scope boundary; how digital wallets (Apple Pay / Google Pay) are handled.
5. **Risk & fraud controls:** 3DS/SCA, risk scoring, velocity limits, sanctions/AML/KYC hooks, and optional ML integration.
6. **Data model & storage:** transactions, ledger entries, settlements, chargebacks, idempotency keys, and immutable audit logs.
7. **Consistency & failure handling:** consistency model, deduplication, retries, exactly-once vs at-least-once processing, and orchestration patterns (outbox / SAGA) for multi-step workflows.
8. **Settlement & reconciliation:** matching the internal ledger against acquirer/provider settlement files, currency conversion, fees, and scheduled payouts.
9. **Scalability & resilience:** throughput targets (e.g., thousands of TPS, p99 latency < 200 ms), backpressure/queueing, high availability, and disaster recovery (multi-region, RPO/RTO).
10. **Security, privacy & observability:** authentication/authorization, encryption, key management, PII/GDPR handling, metrics/tracing/log correlation, and a testing strategy with simulators for external partners.
Explain the key trade-offs and provide a high-level architecture (in words).
Quick Answer: An OpenAI software-engineer system-design screen: design a scalable payment system covering both peer-to-peer wallet transfers and merchant card/digital-wallet payments. It evaluates double-entry ledger design, idempotency and exactly-once/no-double-spend semantics, authorize/capture/refund flows, PCI tokenization, fraud/risk controls, reconciliation and settlement, and scalability, availability, and observability trade-offs.