Two Philosophies
Pessimistic control locks a row while you work so no one else can change it. Optimistic concurrency control assumes conflicts are rare. It lets everyone read freely and only checks for a conflict at commit time.
How The Check Works
- Each row carries a version number or timestamp.
- A transaction reads the version, does its work, then on update says update where version still matches.
- If another writer bumped the version first, the update matches zero rows and the transaction retries.
When To Prefer It
- Workloads with low contention where conflicts are uncommon.
- Web apps where holding locks across user think time is dangerous.
- It avoids lock waits but pays with retries when conflicts do occur.
Key idea
Optimistic concurrency control skips locks and instead validates a version at commit, succeeding cheaply under low contention and retrying when a conflicting write slipped in.