
IDEMPOTENCY
For this task, I am trying to understand what happens when the same transaction runs more than one time. In real systems, this can happen if the network is slow or the request is sent again. First I check the current balance in the accounts table. Query select star from accounts; Here I am just viewing the data. For example, Alice has 1000 and Bob has 500. Now I try to do a money transfer from Alice to Bob. Query begin; update accounts set balance = balance - 300 where name = 'Alice'; update accounts set balance = balance + 300 where name = 'Bob'; commit; Here what I am doing is deducting 300 from Alice and adding it to Bob. After commit, the transaction is saved. Now Alice will have 700 and Bob will have 800. Now I repeat the same transaction again. Query begin; update accounts set balance = balance - 300 where name = 'Alice'; update accounts set balance = balance + 300 where name = 'Bob'; commit; Here I am running the same transfer again. The database does not stop me. So again 300 i
Continue reading on Dev.to Tutorial
Opens in a new tab




