Preparing your design workspace

Loading the problem and your latest saved attempt…

Design Payments for a Short High-Traffic Event

Accept a burst of payments during a short event, charge each one at most once through a rate-limited third-party processor, and give every user one final result.

Problem statement

For this exercise, assume a consumer app runs a one-hour, limited-time event in which many users make payments, such as a limited-time purchase or a contribution.

A user picks an amount between $1 and $500 and pays with a card that is already saved with an external third-party payment processor; the app never sees or stores card numbers. Most traffic arrives in the first five minutes, much faster than the processor will accept charge requests.

The processor accepts an idempotency key on every charge request and, for at least 24 hours, returns the original result when it sees the same key again. It also lets you look up a charge by that key.

It may reject requests above its rate limit, return temporary errors, or time out after it has already charged the card. Design the flow that accepts payment requests during the spike, charges each accepted payment through the processor, retries temporary failures safely, and gives every user one final result.

A user must never be charged twice for one payment, and a payment that the system has accepted must never be lost. Refunds, payouts, fraud checks, currency conversion, inventory, and building the payment processor itself are outside scope.

What to build

  1. A user submits a payment with an amount and an idempotency key and quickly gets an accepted or rejected result; resubmitting the same key returns the same payment instead of creating a new one.
  2. Each accepted payment is charged through the processor at most once, at a rate the processor allows, and temporary failures are retried with exponential backoff.
  3. A user can check whether a payment is pending, succeeded, or failed, and each payment ends with exactly one final result.
  4. Payments that keep failing or whose processor result is unknown move to a dead-letter queue and are resolved by checking the processor, so none stays pending forever and none is charged twice.

At scale

  • For this exercise, assume about 3 million payments during the one-hour event: submissions peak at 8,000 per second for the first 5 minutes and then drop to about 200 per second.
  • For this exercise, assume the processor allows at most 2,000 charge requests per second for this account, a charge call takes 0.3 to 2 seconds, and about 1% of calls fail with a temporary error or time out.
  • For this exercise, target a p99 below 500 milliseconds to accept or reject a submission even at the peak, and give at least 99.9% of accepted payments a final result within 30 minutes of submission; reconciliation resolves the rest.
  • For this exercise, assume clients check status while a payment is pending, for up to 25,000 status reads per second at the peak, and that a status may lag the processor by a few seconds.