Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsA distributed lock coordinates clients, but it does not automatically prevent an expired or paused client from writing to the protected resource. If correctness depends on exclusive access, the resource must reject stale owners—for example, by checking a monotonically increasing fencing token—or the operation must be serialized by a transaction that covers the actual shared state.
What a distributed lock does—and what it does not
A lock service records which client currently holds a lock, often for a limited lease period. That coordination can reduce overlapping work, but the service’s ownership record is not itself a barrier in front of another system’s storage. Unless the protected resource participates in the coordination or validates each operation, it may accept writes from a client whose lease has expired.
As an Amazon Associate I earn from qualifying purchases.
Redis frames lock design in terms of safety and liveness. Mutual exclusion is the safety property: owners should not act as though they hold the lock at the same time. Deadlock freedom and fault tolerance are liveness goals: the system should not remain stuck forever and should continue to make progress under its assumed failures. These are design criteria, not unconditional guarantees for every implementation or timing model. Redis’s live documentation describes a TTL-based algorithm; the client has only the remaining validity window in which to do its work.
Free tools Windows power users keep installed
One-click scans. No signup required.
How a lease expires while its former owner is still running
- Client A acquires a lock with a time-to-live.
- A is paused, or its requests are delayed by the network, long enough that the lease expires.
- Client B acquires the now-available lock and writes to the resource.
- A resumes and sends a write it prepared while it believed it owned the lock.
The lock service can have followed its configured expiry rules correctly, while the resource still receives operations from two successive owners. A TTL helps the system recover when a client crashes and cannot release its lock, but expiry creates a boundary: a paused process can continue from its own perspective after the resource should consider its lease over. Redis’s documentation and Martin Kleppmann’s 2016 analysis both address this distinction.
#1 Best Overall
Fencing tokens: make the resource reject stale owners
A fencing token is an increasing value issued with each lock acquisition. The protected resource remembers the greatest token it has accepted and rejects an operation carrying an older one. If A holds token 41, its lease expires, and B acquires token 42, the resource can accept B’s operation and reject A’s delayed operation when it arrives.
As Kleppmann puts it, “The fix for this problem is actually pretty simple: you need to include a fencing token with every write request to the storage service.” The qualification is essential: the resource must actually validate the token. Every operation performed under the lock needs to carry it, and the resource must compare it against the greatest accepted value. Merely generating increasing values at the lock service does not fence stale writes if the target ignores them.
Rank #2
Kleppmann identifies ZooKeeper transaction IDs or znode versions as possible token sources in the setup he describes. Whatever source is used, the important property is that tokens increase across acquisitions and that the target enforces their order.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →How to do distributed locking
- Define the protected operation. Identify the shared state that must not be corrupted by overlapping work, including any side effects outside the database or service that stores the lock.
- Decide what failure would cost. If duplicate execution is merely wasteful, coordination can be an efficiency measure. If a stale write can damage or corrupt state, assume a lease alone is insufficient.
- Put enforcement at the resource when stale writes matter. Use monotonically increasing fencing tokens and make the target reject older tokens, or use a transaction/serialization mechanism that covers the actual shared operation.
- Choose coordination with its failure boundary in mind. A Redis lock, a consensus-backed service, a database transaction, and a queue-based design make different trade-offs in availability, complexity, and what they can protect.
- Define recovery behavior. Decide what happens when a client pauses, loses its lease, cannot reach a quorum, or retries work whose outcome is uncertain. Make duplicate work harmless where feasible.
Use ownership-safe acquisition and release for a Redis lock so one client does not release another client’s lock. Treat such a lock as approximate under failures, not as sufficient protection for correctness-sensitive writes.
Rank #3
Redis Redlock and the disagreement about correctness
Redis documents Redlock as a multi-node design intended to be safer than a basic single-instance approach. Redis presents mutual exclusion, deadlock freedom, and majority-based fault tolerance among its goals. Those are Redis’s stated design properties and should be understood under the algorithm’s assumptions, including its time-limited validity window.
Kleppmann’s 2016 analysis reaches a different conclusion for work whose correctness depends on the lock. He argues that arbitrary process pauses, delayed packets, and clock behavior can violate the timing assumptions on which Redlock depends, and that Redlock does not provide monotonically increasing fencing tokens. On that analysis, a stale client can still send an operation after another client has acquired the lock. This is Kleppmann’s critique, not a conclusion endorsed by the Redis documentation.
Rank #4
The practical question is not simply whether a lock service reports one current owner. It is whether the system that accepts the protected write can detect and reject a former owner. For correctness-sensitive work, arrange that enforcement at the resource or use a transaction boundary that includes the resource.
Recommended Free Tools
Which alternative fits the failure you need to handle?
| Approach | Pause or network delay | Stale-owner enforcement | Availability during quorum loss | Complexity and fit | Transaction boundary |
|---|---|---|---|---|---|
| Best-effort Redis lock | A client can outlive its TTL from the resource’s perspective; overlap is possible under failures. | Not provided by the lock alone. Pair with target-side token validation if stale writes must be rejected. | Redis’s documentation describes majority-based fault tolerance for Redlock; availability under a particular failure scenario depends on the configured design. | Useful when the lock is an efficiency optimization and occasional overlapping work is tolerable. Ownership-safe acquisition and release are important. | The lock service and protected resource are not thereby placed in one transaction. |
| Consensus-backed coordination such as etcd | Consensus-backed coordination provides documented consistency and coordination primitives, but lease ownership does not by itself stop a stale client from writing to an external resource. | Use resource-side token validation where stale writes matter; etcd lease ownership alone is not external-resource ownership. | etcd’s v3.5 failure-mode documentation says recovery from majority failure requires a majority of members to become available. | Useful when coordination semantics are needed and the operational trade-off is acceptable; it adds a coordination system to operate. | Coordination and an external resource are not automatically covered by a shared transaction. |
| Database transaction or resource-native serialization | Can protect correctness when the transaction semantics cover the shared state and operation; behavior for external side effects is not established by a database lock alone. | Enforcement is within the resource/transaction boundary. A separate external target still needs its own protection. | Availability during quorum loss: not stated by Kleppmann’s article for this general alternative. | Kleppmann recommends a database with reasonable transactional guarantees for correctness-dependent work. The transaction must cover the relevant operation. | Best aligned when the protected state and operation fit inside the same transaction boundary. |
| Idempotent work or queue-based serialization | Can reduce harm from retries or duplicate execution; it does not inherently prevent a stale operation from reaching an unprotected resource. | Stale-owner token enforcement: not stated as an inherent property of this approach. Design the target-side checks if needed. | Availability during quorum loss: not stated in the cited sources for this general alternative. | Consider when duplicate work can be made harmless or a serialized work-claim pattern can replace a broad lock. No performance comparison is established here. | Whether a queue, claim, and target operation share a transaction depends on the system design. |
The etcd documentation describes operations as completing after consensus commit and documents leases and locks as coordination primitives. Its comparison documentation also cautions that owning a lease alone does not guarantee ownership of an external resource. Therefore, consensus-backed coordination can strengthen the coordination layer without removing the need to protect the target from stale writes.
Questions to answer before choosing
- Can stale work cause damage? If not, a best-effort lock may be a reasonable efficiency tool. If yes, require enforcement at the resource or a transaction that covers the protected operation.
- Can the target validate an increasing token? If it can, fencing directly addresses delayed writes from earlier owners. If not, determine whether resource-native transactions or serialization can cover the operation.
- Must work continue when a quorum is unavailable? Consensus-based recovery can require a majority of members to be available, as etcd’s v3.5 failure guide states. Decide whether that trade-off is acceptable for the workload.
- Can duplicate work be made harmless? Idempotency or serialized work claims may be simpler than a broad distributed lock when they fit the operation.
- Do coordination and protected state share a transaction boundary? If not, the lock API cannot by itself make an external side effect atomic with lock ownership.
Sources and further reading
Redis’s live “Distributed Locks with Redis” documentation describes its algorithm and intended properties. Kleppmann’s “How to do distributed locking,” published February 8, 2016, explains the stale-client failure and fencing-token argument. etcd’s v3.4 “etcd API guarantees” and v3.5 “etcd versus other key-value stores” documentation describe its consistency and coordination primitives; its v3.5 “Failure modes” guide addresses recovery after majority failure. For a broader treatment of distributed systems, Kleppmann’s Designing Data-Intensive Applications is a relevant further read.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




