25/28
Part 6 of 6 · Follow-upsLearn and do

A fencing token stops a worker whose lease ran out

Here's the follow-up that catches most candidates. w1 reserves a. Its machine freezes for 40 seconds, longer than the lease. The lease ends, and w2 takes a and writes its result. Then w1 wakes up and, not knowing any time passed, writes its own result over w2's.

The queue refused w1's ack, but the ack comes after the write. The queue can't stop a write to some other system. That system has to stop it.

The fix is a fencing token. The lease number already grows with every reservation, so hand it to the worker with the task. The worker sends it with every write. The store where results go remembers the highest token it has seen for each key and refuses a write with a lower one. w2's lease is newer, so its token is higher, and w1's late write loses.

Predict

The store has seen token 2 for key a. Then a write with token 1 arrives, and then one with token 2 again. What does the store accept?

Pick an answer above to see the rest