architect-handbook

Software Architect Handbook

View on GitHub

Optimistic Offline Lock

Prevents conflicts between concurrent business transactions by detecting a conflict and rolling back the transaction.

Overview

Optimistic Offline Lock solves the problem of lost updates and inconsistent reads by validating that the changes about to be committed by one session don’t conflict with the changes of another session.

A successful pre-commit validation is, in a sense, obtaining a lock indicating it’s okay to go ahead with the changes to the record data. So long as the validation and the updates occur within a single system transaction, the business transaction will display consistency.

Optimistic Offline Lock assumes that the chance of conflict is low. The expectation that session conflict isn’t likely allows multiple users to work with the same data at the same time.

Source Code Management (SCM) system uses Optimistic Offline Lock. When it detects a conflict between programmers it usually can figure out the correct merge and retry the commit. A quality merge strategy makes Optimistic Offline Lock very powerful not only because the system’s concurrency is quite high but because users rarely have to redo any work.

How It Works

For a business transaction to not corrupt record data it must acquire an Optimistic Offline Lock for each member of its change set during the system transaction in which it applies changes to te database.

When to Use It

The correct approach to concurrency management will maximize concurrenct access to data while minimizing conflicts.