Distributed Lock Split-Brain & Monotonic Fencing Tokens
Learn why TTL-based distributed locks fail under GC pauses and network partitions, and how monotonic Raft term/index fencing tokens enforce linearizable writes.
Two workers concurrently write conflicting state to the ledger after a 14-second stop-the-world GC pause, even though both workers acquired a 10-second distributed lock.
ledger_fencing_token_rejections_total == 0 AND ledger_duplicate_settlement_anomalies_total > 0A worker holding a 10s lease lock can freeze for 14 seconds during a JVM/Go GC pause, hypervisor steal, or TCP retransmission stall. While frozen, its lease expires and the lock service grants a fresh lease to Worker B.
When Worker A wakes up, it still believes it holds the lock and sends a stale write to the storage server, overwriting Worker B’s newer committed state.
Only the storage layer can prevent split-brain writes: the consensus lock service (etcd/Raft) must issue a strictly increasing fencing token (e.g., Raft revision / term+index), and the storage server must atomically reject any write whose token is less than the highest token already applied.
Worker A holds a 10s Redis/etcd lock, freezes for 15s during a GC pause, and wakes up to write to PostgreSQL after Worker B already took the lock. What guarantees safety?
- Confirm every mutating write guarded by a distributed lock passes a monotonic fencing token validated inside the storage transaction.
- Add a chaos test injecting SIGSTOP (15s pause) on Worker A while Worker B acquires the lock and writes, verifying Worker A’s delayed write is rejected.
- Keep Raft nodes on dedicated low-latency NVMe disks so WAL fsync p99 stays under 10ms.
Can Redis Redlock replace storage-side fencing tokens?
No. Any wall-clock lease algorithm without a strictly monotonic fencing token verified by the storage engine remains vulnerable to process pauses and asymmetric network delays.
Why does Raft quorum require 2f + 1 nodes (e.g., 3 or 5, never 2)?
Any two majorities in a 2f+1 cluster overlap by at least one node, guaranteeing the newly elected leader always sees the highest committed term and index.
What causes accidental Raft leader elections in healthy networks?
Slow disk fsync latency (e.g., shared noisy EBS volumes) stalls Raft WAL appends longer than election_timeout, causing followers to start spurious elections.