← Lessons

quiz vs the machine

Platinum1740

System Design

Returns and Refunds Flow Deep Dive

Reversing a sale and restoring stock and money correctly.

6 min read · advanced · beat Platinum to climb

The reverse pipeline

A return runs the order backward: the buyer requests it, ships the item, the warehouse inspects it, and only then does money move and stock return. Each step needs its own state.

State and money

  • Model the return as its own state machine: requested, label issued, received, inspected, refunded.
  • Refund only after inspection confirms condition, or refund early and accept some loss for speed.
  • Make refunds idempotent so a retried refund does not pay twice.

Inventory effects

  • Restock only sellable returns; route damaged items to a separate disposition.
  • Update the ledger so a restocked unit becomes sellable again without inflating counts.

Key idea

A return is a reverse order modeled as its own state machine, where money moves idempotently after inspection and only sellable items restock into the inventory ledger.

Check yourself

Answer to earn rating on the learn ladder.

1. Why model a return as its own state machine?

2. Why must refunds be idempotent?

3. Why route damaged returns to a separate disposition?