I'm following this guide to build a stellar exchange. https://www.stellar.org/developers/guides/exchange.html
It's nothing too serious, I'm mostly just doing it to have some fun and learn more about stellar because I love the technology. I have deposits working great, but I have a question about submitting withdrawals to the stellar network.
According to the guide, when a user submits a withdrawal to my exchange, I deduct the amount from their balance and create a row in my database to indicate a withdrawal of state 'pending'. Then, I have a background job running that will query for all withdrawals that are pending and create a stellar transaction for them and submit it to the network. Finally, mark the database row as ‘done’.
My problem is that what happens if I successfully submit the transaction to the stellar network but something happens (network error, server crashes, etc etc) and the database never updates the row to be ‘done’. When the server restarts, the background job would see the same row as being ‘pending’ still and resubmit the transaction, effectively double withdrawing from my account.
How do most exchanges guard against this?