A fencing token is a monotonically increasing authority number issued by a trusted coordination mechanism. The actual resource remembers the highest accepted token and rejects writes with older tokens. Suppose an old worker with token 41 pauses. A new worker obtains 42 and writes. When 41 resumes, the storage service itself rejects 41 rather than trusting the worker to notice its expired lease.
Token checks must be atomic with the protected action and durable across the relevant failures. Checking once at the worker and then issuing an unfenced write leaves a race. Fencing orders accepted authorities; it does not undo a completed external action or turn a non-idempotent request into an idempotent one. The resource’s API and failure model determine whether this pattern can protect it at all.
Define which resource the authority protects
A token must have a defined scope. Suppose coordination issues increasing tokens separately for file A and file B. Token 8 for A cannot be compared meaningfully with token 12 for B unless the system explicitly defines a shared authority order. The resource should associate its remembered maximum with the same protected object or authority domain used by the coordinator. Otherwise, an unrelated operation can incorrectly fence valid work or an old operation can evade the intended comparison. Monotonicity is a property of a specified sequence, not every number in the system.
Resource enforcement also requires trustworthy issuance and request attribution. If any worker can invent token 1000000, numerical comparison alone lets it displace legitimate owners. Authentication can establish that an authorized coordinator issued a token or that a particular worker sent a request. It does not prove that an authorized worker behaves honestly. The crash-fault examples assume participants follow their protocols and do not forge authority evidence. A system facing malicious clients or workers needs access control and evidence validation in addition to an ordered counter. This lesson's token table is not a Byzantine protocol.
Protection across several resources requires separate reasoning. A worker can update one fenced file and crash before updating a second. Each file may reject stale owners correctly while the pair contains an incomplete business operation. Fencing prevents a particular class of stale-authority action. It does not provide an atomic transaction across the files. Likewise, protecting a database row does not protect an external email or payment that bypasses that row's enforcement. Locate the actual irreversible mutation before claiming that a lock, lease, or token covers it.
For a final guided case, imagine a report worker that reads a price, computes an invoice, and later submits it to storage. A linearizable read can establish a valid price observation during the read interval. It does not promise that the price stays unchanged throughout computation. A fencing token can exclude an older worker's delayed write after a newer token has been accepted. It does not establish that the invoice used the current price at submission. That business rule needs its own atomic version check or transaction at the relevant authority.
These distinctions determine the failure response. A server lacking current read authority should wait, redirect, reject, or explicitly offer a weaker read contract. A worker rejected by fencing must not retry the same obsolete action without tokens. A current worker uncertain whether its action completed needs an operation-status or retry contract, rather than a new authority number alone. The next lesson develops stable request identities and atomic durable result records. Those records solve duplicate business effects, a different problem from stale leadership and insufficiently applied state.