Implementing atomic transactions using data stores

I have a new idea which only requires 4 UpdateAsync calls, the last of which can be saved for later if the budget is low. Player1 is initiating a transaction with player2.

The first call updates and locks player1’s data, storing relevant details about the transaction.
The second call validates the transaction against player2’s data, updating it if valid, and leaving a success/failure note.
The third call unlocks player1’s data, reverting it if player2’s data has a failure note.
The fourth call, which can be saved for later, cleans up the success/failure note from player2’s data after player1’s data is unlocked.

Player1’s data has to be locked in case a rollback is necessary. Player2’s data doesn’t need to be locked and only needs to store a tag indicating the result of the transaction, and player1’s data is unlocked after getting the result.

2 Likes