⌘K
Flycodx

Optimistic vs Pessimistic Locking

Optimistic vs Pessimistic Locking

MediumDatabases0% accepted

Two users edit the same inventory record at once and one overwrites the other (lost update). Compare optimistic and pessimistic locking to prevent it. Cover: how a version/timestamp column enables optimistic concurrency, when SELECT ... FOR UPDATE (pessimistic) is better, and the deadlock risk of locks.

Approach

Optimistic: no lock; check a version column on update and retry on conflict — great for low contention. Pessimistic: SELECT FOR UPDATE locks the row up front — better for high contention but risks deadlocks/blocking.

Scenarios & Expected Answers

No example scenarios for this problem.

Sign in to continue

Create a free account to view answers and mark progress.

  • Free forever — no credit card
  • Theory Q&A with detailed answers
  • Points, streaks & leaderboards
Auto Save On