Optimistic Locking
PronunciationOP-tih-MIS-tik LOK-ing
Definition
Optimistic locking lets several users work freely and checks at save time, usually with a version number, that nobody else changed the row meanwhile. If someone did, the save fails and is retried.
Where you hear it
In ORM features (version columns), web forms where two people edit the same record and conflict errors.
Examples
UPDATE ... WHERE id = 7 AND version = 3affects 0 rows, so someone else saved first.Show the user the conflict and let them reload.
Two editors opened the same article, and the second save was rejected because the version had changed.
Common mistake
Using it when conflicts are very frequent. Constant retries waste work; a lock may fit better.
Don't confuse with
Pessimistic locking, which locks the row first so others must wait.
Say it at work
- In a meeting or chat
Add a version column and check it on update.
- In an email or ticket
Conflicts are rare here, so optimistic is fine.