Imagine we have a banking application.
A user has ₹500 in Account A and wants to transfer money from Account A to Account B.
Now suppose two requests arrive at almost exactly the same time:
At first, this may look simple. For every transfer, our backend should:
The problem appears when these operations happen concurrently.
Suppose Account A initially contains:
₹500
Both requests read the balance before either request has updated it.
Initial Balance = ₹500
Request 1 reads → ₹500
Request 2 reads → ₹500
Both requests conclude:
"There is enough money available."
Now: