Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Refund Processing Workflow

Take a customer's refund request from submission through a policy decision, a possible item return or agent review, and payment back to the original card, paying each refund exactly once even when the payment provider times out, answers late or goes down.

Problem statement

Design the backend workflow that handles refunds for a large online store.

For this exercise, assume a customer can ask for a refund of one or more items from a delivered order within 30 days of delivery, and that each order was paid with one card.

The store's refund policy decides each request: an item that costs less than $25 is refunded without being sent back; any other item is refunded only after the warehouse reports that the returned item has arrived; and a request worth more than $500, or one that an existing fraud-check service flags, is decided by a support agent instead.

A support agent can also issue a partial refund on an item, for example $10 back for a damaged box. The total refunded for an item may never exceed what the customer paid for it.

Money goes back through an external payment provider.

For this exercise, assume its refund call accepts an idempotency key and treats repeated calls with the same key within 24 hours as one refund; it usually answers within 2 seconds, but some calls time out with no answer, some results arrive later through a webhook, and you can look up a refund by its key at any time.

If the provider permanently refuses a refund, for example because the card has been closed, the customer gets store credit for the amount instead.

Customers and support agents must be able to see where each refund stands. The order system, the warehouse, the fraud-check service, the notification service, the store-credit service and the payment provider already exist; you design the refund workflow between them.

Exchanges, split payments and the rules engine itself are out of scope.

What to build

  1. A customer can request a refund for items in a delivered order and immediately get a refund ID and a status; submitting the same request again does not create a second refund.
  2. Each request is approved, rejected with a reason, held until the returned item arrives, or sent to a support agent, according to the refund policy.
  3. An approved refund is paid back to the original card exactly once and never more than was paid for the item, even when the payment provider times out, answers late or is down; a permanent refusal leads to store credit instead.
  4. Customers and support agents can see each refund's current status and history, and refunds that stop moving are noticed and acted on.

At scale

  • For this exercise, assume about 2 million refund requests a day, about 25 a second on average and up to about 150 a second for several days after a large sale.
  • For this exercise, assume the payment provider accepts at most 200 calls a second from the store, lookups included, and has had outages of up to an hour.
  • For this exercise, assume a customer gets a refund ID within 1 second, and a refund approved without a return or review is sent to the provider within a minute when the provider is healthy.
  • For this exercise, assume no refund may ever be paid twice or exceed the amount paid, and finance compares every day's refunds with the provider's daily settlement report.