Software Design

Pessimistic Locking with SELECT FOR UPDATE

UML Sequence Diagrams · made in Skemio

Sequence diagram demonstrating how Client 1 and Client 2 compete for a database row, where Client 2 is blocked until Client 1 commits.
Sequence diagram demonstrating how Client 1 and Client 2 compete for a database row, where Client 2 is blocked until Client 1 commits.

What it shows

  • SELECT FOR UPDATE locks matching rows inside an active transaction.
  • Concurrent transactions queue at the database level until COMMIT/ROLLBACK.
  • Prevents race conditions in high-contention, low-latency financial ops.

The takeaway

Pessimistic locking guarantees strict serial access at the cost of queuing concurrent transactions.

More uml sequence diagrams