⚡THE SHORT ANSWER
A critical misconception in distributed engineering is believing that 'holding a distributed lock guarantees exclusive write access to storage.' In real-world environments, Client 1 acquires a distributed lock with a 10-second lease and begins preparing a write. Suddenly, Client 1 experiences a 15-second Stop-the-World GC pause, OS thread starvation, or cloud virtualization freeze. While Client 1 is frozen, its 10-second lock lease expires. The lock service grants the lock to Client 2, which performs its write and commits. Then, Client 1 wakes up from GC: believing it still holds the lock, Client 1 blindly executes its stale write, overwriting Client 2's newer data and corrupting storage. Martin Kleppmann proved that distributed locks CANNOT protect shared storage without Fencing Tokens: the lock manager issues a monotonically increasing sequence number (v=33, 34, 35) with each lock grant. The storage layer checks the token on every write (WHERE token >= last_seen_token), instantly rejecting Client 1's stale write (v=33) because Client 2 already committed at v=34.
Engineering Handbook & Failure Dynamics
6-Dimensional Architecture Breakdown⚙️1. Underlying Mechanism
Execution🎯2. Appropriate Use Context
Scope⚠️3. Production Failure Modes
P0 Risk📡4. Diagnostic Signals & Telemetry
Telemetry🛡️5. Prevention & Safeguards
Safeguards⚖️6. Architectural Trade-offs
Trade-offCase Study (TinyCTO In-Field Example)
A media processing pipeline used distributed locks to ensure only one worker rendered a video to S3 at a time. Worker 1 acquired the lock, but experienced a 40-second JVM full GC pause. The lock timed out, and Worker 2 took over, rendered the 4K video, and saved it to S3. When Worker 1 woke up, it uploaded its unfinished 720p draft over Worker 2's completed 4K file. The engineering team added monotonically increasing fencing tokens from etcd and enabled S3 Object Lock conditional constraints (x-amz-expected-bucket-owner with metadata fencing). When Worker 1 tried to upload, S3 rejected the stale token, permanently protecting completed renders from corruption.
Interactive Concept Drills
2 CardsWhy does a client-side distributed lock fail to protect shared storage during a GC pause?
How does a Fencing Token solve the stale write problem?
Distributed Lock Invalidation: Fencing Tokens & Asynchronous Storage Leases — Technical FAQ
Who originally published the formal critique of Redis Redlock and proved the necessity of fencing tokens?
Martin Kleppmann (University of Cambridge / author of Designing Data-Intensive Applications) in his famous paper 'How to do distributed locking'.
Can Redis generate monotonically increasing fencing tokens?
Yes, using atomic `INCR` commands inside the lock acquisition script, though consensus systems like etcd or ZooKeeper provide stronger linearizable guarantees across network partitions.
🤖 AEO & Key Facts Summary
Key Architectural Facts
- ▸
Distributed locks without fencing tokens CANNOT protect shared storage from corruption.
- ▸
GC pauses, OS thread starvation, and VM freezes cause lock leases to expire silently.
- ▸
Fencing tokens provide monotonically increasing version numbers (100 o 101 o 102).
- ▸
Storage MUST enforce conditional check-and-set guards (
WHERE token >= last_seen).
Common Misconceptions
- ✗
Misconception: A distributed lock with a long TTL (e.g. 5 minutes) makes fencing tokens unnecessary (False: Pauses and network splits can exceed any arbitrary timeout).
- ✗
Misconception: Redlock guarantees absolute safety without storage-side checks (False: Storage must validate fencing tokens to prevent split-brain writes).
Decision & Governance Guidance
Incorporate a monotonic fencing token column into every shared database entity guarded by locks. Use etcd or ZooKeeper linearizable revisions for distributed leader elections and leases.
Authoritative Sources & Standards
- [OFFICIAL_DOCUMENTATION]How to do Distributed Locking: Martin Kleppmann on Fencing Tokens— Martin Kleppmann (University of Cambridge)
