Design a Payment System

ConsistencyPlatform OpenAI

Design the payments service for a subscription and usage-billing product. Customers pay with cards through an external payment processor. The service charges them, records every movement of money, and stays correct when networks fail halfway through.

Functional:

  • Charge a customer for a subscription renewal or a usage invoice.
  • Refund all or part of a charge.
  • Show a customer their payment history and current balance.
  • Handle processor webhooks for asynchronous outcomes such as successes, failures, and disputes.

Non-functional:

  • Never charge a customer twice for the same invoice, even when a request is retried after a timeout.
  • Never lose a successful charge: if the processor took the money, our records must show it.
  • Money records are append-only and auditable.
  • The checkout call returns in under 2 seconds at p95, though the processor sometimes takes 30.
  • 5 million paying customers.
  • 3 million charges on the first of the month, most within a few hours; 200,000 on an average day.
  • Webhooks arrive at up to 1,000 per second, sometimes out of order and sometimes more than once.

Tax calculation, invoicing PDFs, and fraud scoring.

System design
Loading editor...