SDE & MLE Prep

Distributed Lock Service (ZooKeeper / Chubby / etcd)

Requirements: mutual exclusion across processes on different machines, leader election, safety under crashes and network partitions.

clients -> lock service cluster (3 or 5 nodes, Raft/ZAB consensus, replicated log)
   acquire: create ephemeral sequential node /locks/job-000042 (tied to client session)
            lowest sequence number holds the lock; others watch their predecessor
   release: delete node, or session expires (heartbeat lost) -> automatic release
   every grant carries a monotonically increasing FENCING TOKEN
storage service rejects writes with a token older than the last one seen

Deep dives: consensus (majority quorum) keeps the lock table consistent through node failures; leases with heartbeats free locks of dead clients — but a paused client (GC, network) may still think it holds the lock → fencing tokens make the protected resource reject stale holders; Redis single-node locks (SET key val NX PX 30000) are fine for efficiency locks, not for correctness (Redlock is debated); watch the predecessor only (avoid herd effect).