Last Minute Notes
  • Github
  • Docs
  • Learn
    @sayanstwt
Lessons
0/37 done
  • CAP & PACELC
  • Consistency Models
  • Time & Ordering
  • Consensus with Raft
  • Locks, Leases & Fencing
  • Isolation Levels & Anomalies
  • 2PC & Sagas
  • Idempotency & Exactly-Once
Learn/System Design/Distributed Systems

Locks, Leases & Fencing

7 min Advanced 7 steps

Why a distributed lock needs a fencing token to be safe.

Lock
none
Client AClient BLock serviceStorageread file (v1)read file (v1)
request reply failure
In this lessonStep 1 of 7
  1. The problem
  2. Lock
  3. Lease
  4. Pause trap
  5. Fencing
  6. Avoid it
  7. Recap
Step 1 / 7problem

Two writers, one resource

Two processes read the same file, edit it, and write it back. B's write lands last and A's edit disappears.

A distributed lock is meant to stop this: only the holder may modify the resource.

Key idea

Concurrent read-modify-write cycles across processes lose updates unless something serializes them.

←→ step·R replay·Space pause

You'll learn

  • How leases stop a crashed holder from blocking forever
  • Why a lock alone is not enough
  • How fencing tokens make the storage reject stale writes
  • When to avoid the lock entirely
Read the full notesDistributed Systems, 5