I attended an interview today and came across an interesting question:
What problem, if two request with UPDATE action will execute concurrently in sql?. I knew we have optimistic locking and pessimistic locking approach to resolve this. I am just completely stuck with this idea in my head!
Optimistic locking: During this time, when i check the timestamp (where mytimestamp = oldtimestamp). What happens if request 1 and request 2 will reach to this point at the exact same time (I mean completely exact)? => i am stuck at this point!
Pessimistic locking : (In Exclusive lock mode)
2.1. When the client looses connection with server, the lock still exist in Db and other client cannot do anything => How to resolve this kind of issue?
2.2. And also when requests come and acquire the same lock( At read moment ) at the exact same time => what happen in this case?
Please advice on this problem because i am very interested in the solution on how to resolve this in real time scenario.
If you have any question, please add to the comment section.
Edit:
I also refer this article. See my attachment for more clear.
Thank you.