jargon

Backend & systems·Concurrency and coordination

you take a lock on the row up front with SELECT FOR UPDATE, so everyone else waits until your transaction ends.

Pessimistic locking

Also calledSELECT FOR UPDATE, row lock

Preventing conflicts by acquiring an exclusive lock before reading data you intend to modify. It guarantees you will not have to redo the work, at the cost of blocking others and creating deadlock potential. The right choice on genuinely contended rows, on long operations you cannot cheaply retry, and anywhere the retry has side effects.

Commonly confused with