Try
↑ ↓ move↵ openesc close

Interview prep / Locks, leases and fencing

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

Describe a sequence of events in which a client that correctly acquired a lock still writes data it should not have.

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

A strong answer

The client acquires a lease on the lock and starts its work. Before it writes, it stalls: a garbage collection pause, a swapped out page, a frozen virtual machine, or a slow disk. The lease expires at the lock service while the client is stalled. The service hands the lock to a second client, which does its work and writes.

The first client wakes up. From its point of view no time has passed. It sends the write it had prepared. Storage has no idea the lease is gone, so it accepts the write, and the first client's stale data lands on top of the second client's.

Every component did its job. The lock service expired the lease on time, the second client held a valid lock, and the first client was never told it lost anything. The fix has to be somewhere the stale write can be recognised, which is at storage.

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