Search code examples
sqldatabasedatabase-designdistributed-computing

Optimistic locking definition: expressed in terms of "lost update" and "stale read" detection


I am building a data service that must provide optimistic locking. If my service throws an exception upon detection of either a "lost update" or a "stale read," is it correct to say that my service implements optimistic locking? If not, what additional capabilities am I missing?


Solution

  • Optimistic locking is a protocol to avoid undoing intermediate third-party updates or intermediate third-party deletes that were issued in between an updater reading a resource and the same updater issuing an update(/delete) to that same resource.

    But the essential characteristic of optimistic locking is that it achieves this without taking actual locks. You can't say you've implemented optimistic locking if you achieve the aims by taking actual locks.