Optimistic Locking
In contrast to Pessimistic locking, we allows multiple concurrent users to attempt to update the same result
Common way to implement Optimistic Locking:
- Version number
- Timestamp
- less common due to server clock can be inaccurate
Version number
Every single time the application write a row, it will increase the number.
Before the second user writing, it check if the next version has not been written. If it's different than what we expect it to be, we marking as conflicts