menu
Optimistic Concurrency Control (OCC) is a technique used in computer systems, particularly in databases, to manage concurrent access to shared resources without resorting to locking mechanisms that can potentially introduce performance bottlenecks and contention.

Imagine you have a group of friends trying to update a shared document online at the same time. Optimistic Concurrency Control is like letting everyone make changes freely and then checking for conflicts later.

Here's how it works:
  1. Checking Out the Document: Each friend checks out the document and sees a version number (like "1.0"). This tells them the state of the document when they started.
  2. Making Changes: Friends start making changes to the document without telling each other. They trust that conflicts are rare.
  3. Checking Back In: Before saving their changes, each friend checks the version number again to make sure nobody else has made changes in the meantime.
  4. Conflict Check: If someone else made changes (maybe the version is now "1.1"), it means there's a conflict. Friends are notified, and they need to figure out how to resolve the conflicting changes.
  5. Saving Changes: If no conflicts are found, the changes are saved, and everyone's updates are combined.