All system design challenges
#73 Policy Evaluation/Sagas

Cancellation and Refund System

Cancel bookings according to each supplier's policy and refund exactly the right amount, exactly once.

Asked at Expedia Airbnb Stripe

What is being asked

Design cancellations and refunds for a travel site. "Free cancellation until 48 hours before check-in, then one night's charge" for a hotel; "non-refundable except taxes" for a flight. The customer clicks Cancel; the system must cancel with the supplier, work out the refund and return the money.

Requirements

Functional

  • Show the refund amount before the user confirms.
  • Cancel with the supplier, then refund to the original payment method (or as travel credit).
  • Partial cancellations: one passenger, one night, one leg of a package.

Non-functional

  • Never refund twice; never refund without cancelling.
  • Survive supplier timeouts and payment gateway failures.
  • Full audit trail for disputes.

Design

CustomerCancellation APIPolicy evaluatorCancellation workflowSupplier adaptersRefund serviceWorkflow statePayment gateway
Boxes are services; rounded shapes are data stores and queues.
  1. Policy evaluator applies the policy stored with the booking (the one the customer agreed to), not the supplier's current policy, and returns a quote.
  2. The workflow runs as a durable saga: cancel with supplier → record the penalty → create the refund → mark complete. Each step is retried with backoff and is idempotent.
  3. Refund service sends the refund with an idempotency key derived from the cancellation ID.
  4. Webhooks from the gateway update the refund to SUCCEEDED or FAILED; failures go to a manual queue.

Key decisions and trade-offs

  • Store the policy at booking time. Policies change; disputes are decided by what was shown when the customer booked.
  • Cancel first, refund second. Refunding before the supplier confirms risks paying out for a booking that still stands.
  • Durable workflow engine (or a state table + workers) instead of one long request: supplier cancellations can take minutes.
  • Travel credit vs cash refunds: credit is instant and keeps revenue, but needs its own ledger.

Follow-up questions

  • The supplier cancelled but your refund call timed out. What happens next?
  • How do you refund a package where only the hotel is refundable?
  • An airline cancels the flight itself. How does the flow change?
  • How would you detect refund fraud?
Log in to tick off the challenges you have worked through. Log in