← Questions
Make a charge-then-record payment flow safe against crashes and retries
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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:
- The charge succeeds but the database write never happens, or a retry charges twice. How do you make the operation idempotent and recoverable?
- 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.
- 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?
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
