Posts

Showing posts with the label optimistic locking

Optimistic Locking

Image
Introduction In contrast to Pessimistic Locking which I explained in the previous article, Optimistic Locking is suitable for use in cases where two people modifying the same data row rarely occurs Therefore, it allows everyone to read and modify data freely and the check is only performed when executing an UPDATE If this row has not been modified by anyone, the UPDATE will proceed normally If someone has already modified this row beforehand, it will report an error and request a user retry To implement Optimistic Locking, you do not use any row-level lock commands, but will instead implement it yourself in code via a version column (or an updated_at column) in the table When you SELECT row data, you first retrieve the value of the version column After performing the required business logic processing When you UPDATE that row, you check whether the version matches the previously retrieved value If no one has UPDATE d it yet, the version remains unchanged, you will get that row to UP...