KatInterview

Designing a Fault-Tolerant Courier Payout Pipeline

System DesignModel answer
MediumModel answerSystem Designidempotencyreliabilitypayments

Last updated

Design the hand-off from a courier pay calculation to an external payment service so every courier is paid the correct amount exactly once, even through outages and ambiguous timeouts.

A delivery marketplace calculates earnings for its couriers from order events. Earnings accrue per minute, scaled by how many orders the courier has in progress at that moment, and minutes in peak periods are paid at double the rate. Once an amount has been calculated, the platform calls a separate payment service to move the money to the courier.

The calculation logic is already written. You are now asked: what happens if the payment service is down or behaving badly?

Design the hand-off between the pay calculation and the payout so that every courier is eventually paid the correct amount, exactly once, even during outages, slow responses, and ambiguous failures.

In your answer, cover:

  • The different ways the payment call can fail, and why they need different handling.
  • What the platform stores, and when, so that no obligation is lost.
  • How retries work without ever paying twice, and how you avoid overloading the payment service when it comes back.
  • How you detect and repair mismatches between your records and the payment service's records.
  • What couriers see in the app and how operators learn that payouts are stuck.

State any assumptions you make. Good questions to raise: how often couriers are paid (per order, daily, weekly, instant cash-out), whether the payment service supports idempotency keys and status lookup, how much delay is tolerable, and whether the service is internal or a third party with rate limits.

Hints

Hint 1

Separate three outcomes of a payment call: a definite failure, a definite success, and a timeout where you do not know what happened. The third one is the dangerous one for double payment.

Hint 2

Write the amount owed to your own database before calling the payment service, give it a stable unique identifier, and send that identifier with every attempt so the receiver can recognize repeats.

Hint 3

Think about what happens when the service returns after hours of downtime: thousands of queued payouts retry at once. Consider backoff with jitter, a circuit breaker, and a rate-limited drain. Also plan a periodic reconciliation job as the safety net.