ConcurrencyIntermediate
Optimistic vs pessimistic locking
“When do you use each?”
What this tests
- Concurrency control strategy by conflict rate
Answers by level
Read the beginner answer first and notice what is missing.
Pessimistic takes the lock before reading (SELECT … FOR UPDATE); others wait. Correct by construction, at the cost of contention and deadlock risk — right when conflicts are likely and a retry would be expensive (money, inventory).
Optimistic takes no lock; it writes with a version check and retries on zero rows updated. No waiting, no deadlocks, at the cost of a retry loop — right when conflicts are rare (editing a profile, a document).
Green flags · Red flags
Strong green flag · Frames it as expected-conflict-rate, not "safer".
Green flags
- Decides by conflict rate
- Knows both mechanisms concretely
- Notes the failure mode of each
Red flags
- Always pessimistic
- Cannot describe the version-check mechanism
Follow-up questions
F1
Which for a collaborative document with rare simultaneous edits?
Scenario
A seat-booking system has high contention on popular events. Which strategy, and why not the other?