AdvancedAbout 15 min

    Unreliable Clocks & Fencing Tokens

    Read the full article on Substack

    7 min read.

    See a paused process wake up on an expired lease and corrupt data, how fencing tokens stop it, and how clock skew makes last-write-wins drop newer writes.

    Think of it this way: A fencing token is like a numbered ticket at a deli counter. If someone dozes off holding ticket 33 while the counter has already served 34, the clerk refuses 33 when they finally wake up and wave it, no matter how sure they are it is their turn.

    Client 1Client 2Lock serviceStorage
    Storage holds
    nothing yet
    Lease is with
    nobody
    Thinks it has the lease
    nobody

    Two clients share one file. A lock service hands out a lease so only one of them writes at a time.

    1/9

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    How a fencing token saves the file

    Sequence

    Order the events from the first lease to the stale write being refused.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    6. 6Drop a step here
    6 pieces left to place

    Quiz

    8 questions
    Question 1 of 8
    Score: 0

    A client holds a lease, pauses for 15 seconds, and wakes up. What does it know about its lease?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going