
Idempotency Situation
Let me explain duplicate transaction First we have accounts table Alice = 1000 Bob = 500 now we try same transfer again and again. First transfer: BEGIN ; UPDATE accounts SET balance = balance - 200 WHERE name = 'Alice' ; UPDATE accounts SET balance = balance + 200 WHERE name = 'Bob' ; COMMIT ; After first transfer: Alice = 800 Bob = 700 200 is transferred successfully lets run the transfer again BEGIN ; UPDATE accounts SET balance = balance - 200 WHERE name = 'Alice' ; UPDATE accounts SET balance = balance + 200 WHERE name = 'Bob' ; COMMIT ; After second time: Alice = 600 Bob = 900 same operation is applied again and money is transferred again since, database does not know it is duplicate request it will execute again and again so duplicate transactions are allowed the problem is same request runs multiple times money will be deducted multiple times this leads to incorrect balance At the end of the day the database only guarantees that each transaction runs correctly. It doesn’t stop
Continue reading on Dev.to Python
Opens in a new tab


