Make a charge-then-record payment flow safe against crashes and retries

0
Remix

A backend first charges a customer through an external payment provider and then writes the payment to its own database. You are shown code like this (in Java or Python) and asked what goes wrong when the process crashes, the client disconnects or the provider times out between the two steps, and how you would change it. There is little or no coding: explain the failure cases and the fix.

Reported variants of the same discussion:

  1. The charge succeeds but the database write never happens, or a retry charges twice. How do you make the operation idempotent and recoverable?
  2. A refund function retries the provider call up to three times and then marks the refund done. Find its bugs and make it safe to run again.
  3. You are adding a third-party payments API to a service. How do you handle its errors, retry safely, and what do you store about each payment?
MercorTechnical phone screenLast asked Oct 2026
No answer yet. Write the first one; the best answer gets endorsed.