Try
↑ ↓ move↵ openesc close

Interview prep / Locks, leases and fencing

Junior · Locks, leases and fencing · System design interview question

What is a fencing token, and where does it have to be checked?

Sketch your own answer first, then compare it with the one below.

A strong answer

A fencing token is a number the lock service issues with every grant, and it goes up every time. A client sends the token with each write it makes while holding the lock. Storage keeps the highest token it has seen and rejects any write with a lower one.

A stale holder carries a token from before the lock was reassigned. By the time its late write arrives, storage has seen the newer holder's higher token, so the write is rejected. The holder learns it lost the lock from the rejection.

The check has to be at storage, or wherever the protected resource lives. Checking in the client is not enough, because a stalled client checks and then stalls. The resource must be able to say no on its own.

Sources

Learn it by running it

The locks, leases and fencing lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms