Distributed Locks & Logical Clocks
Why wall-clock time lies in distributed systems, Fencing Tokens, and Lamport/Vector Clocks
Difficulty: Advanced · Read time: 9 min · Access: Step-1 Preview + Knoera Pro
How It Works
Physical wall-clock timestamps on separate servers drift and can jump backward or forward during Network Time Protocol (NTP) adjustments, making wall-clock timestamps unsafe for ordering events across machines. Logical Clocks (Lamport Clocks and Vector Clocks) track causal "happens-before" relationships without relying on synchronized hardware clocks. Likewise, Distributed Locks built with Redis, `etcd`, or Apache ZooKeeper require monotonically increasing Fencing Tokens enforced by the storage layer so a Garbage Collection (GC)-paused client cannot wake up and corrupt data after its lock lease expires.
Why It Matters
A notorious distributed systems failure: Client A acquires a 10-second lock lease, freezes for 15 seconds during a Java Virtual Machine (JVM) Stop-the-World Garbage Collection (GC) pause, its lease expires, Client B acquires the lock and updates storage, and then Client A resumes—unaware its lease died—and silently overwrites Client B’s work!
Interactive Architecture Scenarios
- Fencing Token Stopping a Stale GC-Paused Client
- Failure Mode: Unfenced Redis Lock + Zombie Overwrite