3 ms·
Correct me if I'm wrong, but I feel like bank transactions aren't always commutative. Consider: balance = 0 balance += 100 balance -= 50 You can't swap the or
by uryga 10y ago
Correct me if I'm wrong, but I feel like bank transactions aren't always commutative. Consider:
balance = 0
balance += 100
balance -= 50
You can't swap the order of addition and subtraction, because that would mean withdrawing from an empty account, and afaik you can't do that. Is there something I'm missing?
- knucklesandwich 10y agoThere are a couple ways you could do this, though according to jerf in a comment below, banks often don't implement transactions as commutative. Most commonly things like this are done by somehow reifying the operation as data and attaching some information to determine ordering. One way would be to attach a timestamp to bank transactions. By itself, that would be enough to ensure bank transactions commute (but without bounds on clock synchronization, wouldn't guarantee that you see those operations in the order you issue them). You could also require a single consistent read to an account to get a state version number and attach an incremented version of that in your transaction. Ties in both cases could be resolved by account id of the person initiating the transaction.
- vidarh 10y agoYou can execute a withdrawal operation on an empty bank account. E.g. a credit card or a loan account are both accounts that are allowed to go negative, but regular accounts with overdrafts also do, and regular accounts without overdrafts are also often allowed to go negative (but often with prohibitive fees and restrictions attached). It is entirely up to the bank whether or not it will be allowed to complete, but regardless the response from the bank the end result of the operations will be correct, but it may be different (it will be different if the bank will reject an operation in one order, but accept all of them when presented in a different order). You are right that they are therefore technically not strictly commutative in the sense the outcome may differ in edge cases. But the point is that what will not happen, is that you will get incorrect results. E.g. money won't "disappear" or "appear" spontaneously.