Enforce authority at the resource with fencing tokens
Use monotonic grant generations to reject stale effects while separating fencing from leases, authorization, and duplicate suppression.
On this page
The question for today
What you’ll understand
- Explain why a resumed old owner can still issue or deliver operations.
- State the atomic resource-side rule that rejects an older generation.
- Distinguish establishing a fence from merely issuing a newer token.
An old worker can stop responding, lose its lease, and later resume with an operation it prepared before the pause. The new worker may be perfectly entitled to act, yet both can reach a storage service. A fencing token makes the authority generation visible where the effect occurs. Its usefulness depends on enforcement there: a number carried in a request is not protection if the receiving resource ignores it, forgets its history, or checks it separately from performing the update.
Make the generation part of the operation contract
An authority service can issue a strictly increasing generation whenever ownership passes to a new holder. Each protected operation carries that generation and identifies its resource scope. The resource records a high-water mark for the scope and rejects an operation with a lower generation. A resumed holder with an older token can still run code and send requests; it simply cannot make the protected effect after the newer fence is established. This changes the safety boundary from a client's recollection of ownership to a check coupled with the resource's actual state change.
The comparison and effect must be one atomic resource operation under a justified synchronization or transactional mechanism. Checking a token, releasing protection, and applying the write later permits the fence to advance between those actions. The high-water mark also needs a suitable durability and failover contract; forgetting it after restart can make an old generation appear acceptable again. Generations must not silently repeat within the same resource incarnation. If a resource is deliberately recreated, its new identity and old-request rejection need an explicit design rather than an assumption that resetting a counter to zero is harmless.
Issuing a token and establishing a fence are different
Suppose a service issues generation 42 while a resource has only observed 41. A request carrying 41 may still pass a simple high-water comparison until 42 is installed there. Therefore, a proof must define when the new owner is allowed to consider itself active and how it establishes its fence before relying on exclusion. Depending on the system, that can be an explicit resource operation, a validated grant check, or another protocol. Do not infer that the resource has learned a new generation merely because a remote coordinator has assigned it to someone else.
Fencing also has a narrower purpose than duplicate suppression. Many valid operations can carry the same holder generation. Accepting generation 42 twice does not establish whether the second request repeats the first operation or represents new work. Use an operation identity and an idempotency or sequencing contract when retries need that distinction. Likewise, possession of an arbitrary large integer is not authorization; the resource must accept generations only through the intended authority scheme. Clock timestamps are not an automatic replacement for monotonic grants, because skew, repeated readings, and corrections can violate the required generation contract.
Protect every effect that depends on ownership
A worker might update a database, publish an object, and call an external payment service during one ownership interval. Fencing only the database does not automatically protect the other effects. List the effect boundaries and determine which can enforce generations, provide idempotency, participate in a transaction, or support a different coordination mechanism. Even perfect fencing at several resources does not by itself make a multi-resource workflow atomic. Failure recovery must account for which effects actually occurred. Test the resumed-old-owner case with requests delayed across ownership changes, not only orderly release followed by acquisition.
The modular lab isolates why generation reuse is dangerous. Reset, set both modulus m=4 and step a=1, predict when the orbit returns to zero, then Play or Step through four additions. The displayed residue identifies neither age nor unique ownership once it repeats. For any fresh comparison, Reset and re-set both controls. A production fence needs an explicit non-reuse or incarnation policy rather than this toy wraparound. The instrument does not issue grants, persist a high-water mark, validate authorization, or atomically reject a write; those are the mechanisms that make the resource-side rule meaningful.
Work it through
Reject a delayed write after a new fence
A resource high-water mark is 41. Old holder A has a delayed request carrying 41. New holder B is issued 42 and atomically establishes 42 at the resource before acting. Assume token scope and authorization are valid. Track the delayed request and a later retry from B.
B’s fence operation observes 41, accepts 42, and durably changes the resource high-water mark to 42 as part of the protected transition.
A’s delayed request then arrives with 41. Since 41<42, the resource rejects it before applying its effect, even if A still believes its old ownership is valid.
B’s request carrying 42 meets the generation comparison. A repeated copy with 42 still needs an operation identity or another deduplication rule; equality of grant generations cannot tell a retry from a different operation by B.
The old effect is excluded after the fence is established. The token alone does not supply duplicate detection or global atomicity across other resources.
The living notebook
Explore the model
Interactive lab · modular
A reused residue cannot name a unique ownership generation
Reset, set both m=4 and additive step a=1, predict the return to residue 0, then Play or Step through four additions. Each Step advances one modular addition. This instrument illustrates repeated identifiers; it does not implement token issuance, resource-side fencing, or durable state.
- Residue r0
- 0
- Orbit period · m/gcd(m,a)
- 12
- Distinct residues visited
- 1 of 12
Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forFencing needs a generation contract that survives pauses, delayed requests, and recovery. Ordinary comparison of silently wrapped residues cannot preserve that contract.
Pause & reason
Check your understanding
Your turn
Try it yourself
A validated operation carries token 87 while the resource high-water mark is 90. What should happen? If the mark were 87 instead, would acceptance prove that repeating the operation is harmless?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Apply the generation comparison, then distinguish ownership generation from operation identity.
Compare with the solution
At 90, token 87 is rejected without its effect. At 87, equality passes this particular generation test but says nothing about duplicate effects; a separate idempotency or operation-sequence contract is needed.
Keep the idea
Take it with you
- Fencing rejects stale generations at the place where effects occur.
- Atomic enforcement, persistent high-water state, scope, and activation timing are part of the mechanism.
- Generations do not replace authorization, duplicate suppression, or multi-resource transactions.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.