In digital wallet systems like PhonePe or GPay, the same request can sometimes be sent multiple times due to network issues or retries. If the system processes the same request more than once, it can lead to incorrect balances. This is where idempotency becomes important.
To understand this, I performed a simulation using the accounts table with two users, Alice and Bob. Initially, their balances were 600 and 700.
First, I performed a transfer of 200 from Alice to Bob. After executing the queries, the balances became 400 for Alice and 900 for Bob.
Then, I repeated the same transfer operation again, simulating a duplicate request. After running the same queries again, the balances changed to 200 for Alice and 1100 for Bob.
This shows that the system processed the same request multiple times, leading to repeated deductions and credits. The system did not prevent duplicate execution.
From this experiment, it is clear that without proper handling, repeated requests can cause inconsistent data. In real-world systems, techniques like unique transaction IDs or idempotency keys are used to ensure that the same request is processed only once.
This helps maintain correct balances even if a request is sent multiple times.
Top comments (0)