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:

  1. Version number
  2. Timestamp
    • less common due to server clock can be inaccurate

Version number

Pasted image 20230906125559.png

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