concept Backend & software
Distributed leases and fencing tokens
A lease can expire while its holder is paused. When that holder resumes, an old write can still arrive. A fencing token lets the resource reject it if the resource has already accepted a newer token.
What it means
Lease expiry ends a client's turn to write; it does not stop the client from sending a request. A fencing token gives each new lease grant a higher number than the previous grant. A protected resource can reject an old holder's write by comparing the token on the request with the highest token the resource has already accepted.
Try it
Simulation: start with a resource that has accepted token 8 and a writer arriving with token 7. With Resource checks fencing set to yes and evidence set to provided, the resource compares the numbers. Since 7 is less than 8, it rejects the write. Its highest accepted token stays at 8.
Distributed leases and fencing tokens
Show why expired holders can still act and how monotonic fencing blocks stale writes
Resource rejects a token older than its accepted fence.
Token and authority
- Previously accepted epoch8
- Presented epoch7
- Fence checkyes
- Write decisionRejected as stale
- Remembered epoch after decision8
An accepted write is only the modeled fence decision; it is not authentication or a live write. Without enforcement the remembered token need not change.
Evaluated inputs
- Required scenario evidence
- provided
- Resource checks fencing
- yes
- Arriving writer token
- 7 count
- Resource highest accepted token
- 8 count
Fence tokens already issued uniquely and monotonically; equal token allowed for same holder, no authentication, clock sync or live writes.
About this model
The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.
Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.
- Change only
Resource checks fencingtono. The model now admits the same write and leaves the remembered number at8. The writer still presents7, but the resource does not use it to decide. - Use Reset, then change only
Arriving writer tokento9. This write is also admitted, but for a different reason: the check runs,9is newer than8, and the resource advances its fence to9.
Reset returns to the original 8 and 7 example with checking on and evidence provided. Both token inputs must be whole numbers from 1 through 100. A missing or invalid token gives an input error, not a write decision. With valid inputs but Required scenario evidence set to missing, the outcome is unknown. None of these examples sends a real write.
The order the resource sees
Imagine how the first request came to arrive late. Client A gets a lease with token 7 and pauses before sending its write. While A is paused, its lease expires. Client B gets the next lease, sends a write with token 8, and the resource accepts it. When A resumes, it sends the write it had prepared. The request arrives later than B's, but its token identifies an earlier grant.
What matters is that the resource has accepted 8, not just that the lock service has issued 8. Suppose B has its token but has not yet written, and the resource still remembers 7. A's 7 is equal to that fence, not below it. The model permits another write with the same token from the same stipulated holder. It neither asks what time it is nor checks that the caller is that holder.
An arriving token equal to the remembered token is another useful boundary. With checking enabled, 8 versus 8 is admitted and the remembered token remains 8. This assumes another request of the same stipulated epoch; it does not establish that the request is unique or that its caller is authorized.
In practice
To assess a stale-write claim, look for the arriving token, the highest token the same resource had accepted at that moment, and whether it enforced the comparison before admitting the write. A record of lease expiry alone gives you none of those three facts.
The simulation assumes distinct, increasing tokens have already been issued for successive grants. It does not model how to issue them, synchronize clocks, authenticate a writer, or determine its permissions. The useful question is not whether the former holder noticed its timeout, but whether the recipient had seen a newer token and would reject the older one.
Frequently asked questions
Editorial questions based on the listed sources and explicitly labeled local examples.
Can a paused client wake after expiry?
Yes. Lease expiration does not physically stop a paused holder. A cooperating resource needs a mechanism to reject requests from a superseded epoch.
Does checking a token at the lock service suffice?
Not if a paused holder can still reach the resource. The protected resource must enforce the fence, or an equivalent authority mechanism, before accepting a write. The model only represents that resource-side decision.
Can fencing replace authorization?
No. Fencing is a stale-holder protection mechanism, not a decision about who is authorized to operate on the resource.
Why allow equal token?
The model treats a token equal to the current accepted epoch as another permitted request from the same stipulated holder. Fencing rejects stale epochs; it is not per-write uniqueness or caller authentication. Other resource protocols may impose further rules.
Sources & model boundaries
Primary references used for this explanation. The interactive example is an educational model, not a live check.
- How to do distributed locking (author analysis)
resource tokens. Increasing tokens allow a cooperating resource to reject requests older than a token already processed; lease expiry alone does not enforce this.
Checked .
- The Chubby Lock Service
sequencers. A lock generation is included in sequencers; cooperating recipients check validity before accepting operations. Lock delay is explicitly imperfect.
Checked .