Distributed locks and fencing tokens 00:00:01 The projector has two directors A theatre has one shared projector. Editor A receives a temporary right to change its programme and starts preparing the next scene. That right comes with number forty-one. For a moment, everything appears in order. A's process pauses for longer than anybody expected. From the theatre's perspective a vanished editor and a slow editor look remarkably similar. If the lease never expired, a failed editor could keep the entire show waiting. The lease expires, so editor B acquires the next grant, number forty-two. The lease service recognizes only B as current owner. Has that alone made it impossible for A to change the projector? 00:00:47 The old message still exists B sends scene two. The projector switches. This is a new externally visible effect. A successful ownership decision at the lease service did nothing to delete any packets the old editor might have sent earlier. A wakes up and sends its delayed scene-one command. A could even have sent it before the pause and suffered a network delay. In both cases the old message can reach the projector after B. Without a further check, the projector accepts the last arrival and returns to scene one. B owned the lease the entire time this incorrect update was visible. The mistake happened at the resource that actually accepted the effect. 00:01:31 Give each grant an order A fencing token is a grant number that increases with each later ownership grant for this resource. Both editors attach their numbers to their commands. A random identifier can distinguish two grants but cannot by itself say which came later. When B's command arrives, the projector checks the token and records forty-two with the scene update. The check and the write must form one protected transition. Two uncoordinated steps would create a new race. Now replay A's late command. Forty-one is older than the stored forty-two. The projector refuses the change. The check lives where scene data is written, so A's mistaken belief about its own lease no longer decides the outcome. 00:02:21 What does the fence omit? Suppose B repeats the exact same command with token forty-two. The fence distinguishes old owners from newer ones. It does not, on its own, distinguish two commands issued under the same grant. If commands within one edit session also need ordering, add a sequence or operation identifier with the required semantics. Picking a new scene twice and charging a customer twice would need different repeat handling. Restart the projector next. If it loses its highest accepted grant while delayed messages remain possible, old work can become acceptable again. The record enforcing the fence needs durability appropriate to that failure model. 00:03:06 Finish the show The lease solved one problem by allowing the next editor to take over. It could not tell the old editor precisely when time or network delivery would resume. Fencing solves a different problem once the resource has accepted the newer grant. If the underlying resource cannot inspect and enforce a fence, returning a number from a lock service cannot provide that guarantee by itself. The audience keeps seeing scene two. When reviewing a distributed lock, follow the stale owner's message all the way to the last writable resource. That is where the promise either holds or breaks.