select for update
An SQL query that reads rows and locks them for the rest of the transaction.
In more detail
It is how a transaction takes a row lock on the read, so a second buyer waits and then sees the seat is gone. Other transactions trying to lock or update those rows wait until the first one finishes.
Related terms
- row lock — A database lock on one row that makes other transactions wait before changing it.
- pessimistic locking — Locking data when you read it so nobody else can change it until your transaction finishes.
Taught in
- Worked Design One: Ticket Booking, Correctness First — Scalable System Design & Distributed Architecture