I have a balance stored on a server in a database. I would like to have two api's
- addToBalance(amountToAdd)
- subtractFromBalance(amountToSubtract)
My problem is as follows If a user is on a mobile and calls one of these then loses connection we have no way of telling if the balance was updated. So we do not know whether or not to retry.
A solution I came up with was to give the current balance as the client knows it to verify whether there has already been an update, the update should fail if the balance provided does not match the actual current balance. The problem with this solution is, if the balance is updated from elsewhere then the call will fail. We will not know whether to differentiate between the two failures so still do not know whether or not to retry.
Does anyone have a possible solution to ensure that the same call does not get made multiple times to avoid multiple additions and subtractions?
Thanks, Andy.