pessimistic locking
Locking data when you read it so nobody else can change it until your transaction finishes.
In more detail
The second transaction waits and then sees the updated state. It is correct under heavy contention, at the cost of lock waits.
Related terms
- row lock — A database lock on one row that makes other transactions wait before changing it.
- select for update — An SQL query that reads rows and locks them for the rest of the transaction.
- optimistic concurrency control — A way to prevent lost updates by reading a version, preparing a change, and making the write succeed only if that version is still current.
Taught in
- Worked Design One: Ticket Booking, Correctness First — Scalable System Design & Distributed Architecture