Design an Online Payment Processing System
Design a reliable payment path that turns an order into one captured charge and reconciles uncertain provider outcomes.
Problem statement
For this exercise, assume an online merchant platform needs to accept card-like payments for orders through one or more external payment processors. A merchant creates a payment intent with an immutable amount, currency, and order reference, then confirms it using a tokenized payment method.
The system should expose the current status, notify the merchant of durable changes, and support full or partial refunds after capture. Client requests, processor requests, and callbacks may be duplicated, delayed, reordered, or time out after taking effect.
One logical payment must capture at most once, the total completed refund must never exceed the captured amount, and every financial transition must remain auditable.
Keep card-number storage, processor onboarding, foreign exchange, subscriptions, disputes, fraud-model design, and merchant payout settlement outside the first version.
What to build
- A merchant can idempotently create a payment intent for one order, immutable amount, and currency and receive a durable identifier.
- A merchant can confirm an eligible intent with a tokenized payment method and eventually observe one authoritative captured, declined, cancelled, or unresolved outcome.
- A merchant can retrieve payment status and receive authenticated, replayable notifications for durable state changes.
- A merchant can idempotently request full or partial refunds while the system prevents completed refunds from exceeding the captured amount.
At scale
- For this exercise, assume peaks of 10,000 payment-intent creations and 5,000 confirm or refund requests per second across merchants.
- For this exercise, assume durable intent creation completes within 300 milliseconds at p95 and an internally accepted confirm or refund command receives a response within 500 milliseconds at p95, while processor completion may remain asynchronous for minutes.
- For this exercise, assume external processor requests and callbacks are at least once and may be delayed, duplicated, reordered, or return an unknown outcome after taking effect.
- For this exercise, assume financial journal and audit records are retained for seven years, acknowledged internal state survives a process or single-zone failure, and merchant read traffic is five times command traffic.