KatInterview

Keeping Courier Payouts Correct When the Processor Is Flaky

System DesignModel answer
MediumModel answerSystem Designidempotencyretriescircuit-breaker

Last updated

Design a payout pipeline that stays correct and pays each courier exactly once when the downstream payment processor is slow, erroring, or down for hours.

Scenario

You are responsible for a backend service that works out how much each delivery courier is owed and then asks an external payment processor to transfer that money. Couriers receive scheduled weekly payouts, and some can also trigger an instant cash-out from the app and expect an answer within seconds.

The processor is not always healthy. It may be fully down, respond very slowly, hang until your client times out, or fail on a fraction of requests.

Question

Describe how your system should behave during such an outage. Your design should protect two things at once: financial correctness (nobody is paid twice, nobody is silently skipped) and a reasonable experience for couriers and support staff.

Cover at least the following:

  • How you make payout requests safe to repeat (idempotency)
  • Your retry policy, including backoff and jitter, and how you decide which errors to retry
  • When a call should be retried inside the request versus handed off to background processing
  • Circuit breaking and what the system does while the breaker is open
  • How a queue and a dead-letter path help with recovery
  • How you reconcile your records against the processor once it is healthy again
  • What you monitor and when you alert

State any assumptions you make about scale and about the processor's capabilities.

Hints

Hint 1

Ask what a client timeout really tells you. Did the processor receive the request and perhaps execute it, or not? Think about a state for payouts whose outcome you do not know.

Hint 2

Separate errors into those worth retrying, those that never will succeed without human action, and ambiguous ones. Then think about which identifier must stay constant across every attempt.

Hint 3

Scheduled payouts and instant cash-outs have very different latency budgets. Think about what happens to a request that cannot finish within the user's patience, and how to avoid the user submitting again.

Hint 4

Retries and queues give at-least-once delivery. What independent process confirms that your database and the processor actually agree about every payout?