Skip to content
StackDecode
System Design
5. Advanced Database ArchitectureAnimated

Pessimistic Concurrency Control

Lock first so conflicts cannot happen.

The idea

The transaction takes locks before touching data, blocking others.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

Txn 1Row ARow BTxn 2lock A
  • current message
  • earlier
  • failure or attack

Txn 1 locks row A.

step:
1/6
from:
Txn 1
to:
Row A
1/6

Time runs downward. Solid arrows are requests, dashed arrows are replies.

Step by step

  1. 1Acquire locks
  2. 2Read and modify
  3. 3Commit
  4. 4Release locks

Where it is used

High-contention data.

Watch out for

Waiting and deadlocks.

Related