Lab · Distributed data

Clocks & ordering

Three replicas of user:42 take edits on random nodes and copy them to each other. Skew node B's clock and see last-writer-wins drop newer edits; then see Lamport and vector clocks order the edits by what each node had seen.

Try it

Lab time 3.0 s
Node A, holds v10Node Aholds v10clock 3.000 sNode B, holds v10Node Bholds v10clock 3.000 sNode C, holds v10Node Cholds v10clock 3.000 s
  • Node A — holds v10 — healthy — clock 3.000 s
  • Node B — holds v10 — healthy — clock 3.000 s
  • Node C — holds v10 — healthy — clock 3.000 s
  • An edit being copied, with its stamp
Edits
10
Lost silently
3
Problem:
Newer edit lost
0
Kept side by side
0
Merged
0

Numbers add up:10 edits: 3 lost silently (0 of them newer edits), the rest kept or replaced by a later editThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

Ordering
How nodes order edits

Each write is stamped with its node's wall clock; the highest stamp wins.

Traffic and clocks
0 ms
2

Nodes also reply to some edits they receive, so the Edits counter grows faster than this.

Recent edits

EditNodeStampWhat happened
v10B@2158kept
v9A@1978lost: same-time edit dropped
v8A@1855kept
v7A@1705kept
v6C@1484kept
v5A@945kept
v4B@828lost: same-time edit dropped
v3C@816lost: same-time edit dropped

Stamp: a wall-clock time in ms, a Lamport counter (#), or a vector of what each node had seen ([A, B, C]).

What just happened

  1. 2.2sError: B keeps v10 and drops v9 without a word; neither saw the other.
  2. 1.0sError: C keeps v5 and drops v3 without a word; neither saw the other.
  3. 1.0sError: A keeps v5 and drops v4 without a word; neither saw the other.
  4. 0.0sInfo: Last writer wins. Node B's clock runs 0 ms behind.
What this model simplifies
  • Time is slowed so you can watch each copy travel. Network delays here are 60 to 300 ms.
  • Only node B's clock is off, by a fixed amount. Real clocks also drift and jump when they resync.
  • A node sometimes replies to an edit it receives with its own edit 20 to 80 ms later, like a person reacting to a change.
  • Every copy arrives. Real stores also repair nodes that missed copies, with read repair and anti-entropy.
  • There is one key. A real store keeps a clock per key, and vector clocks there are pruned as they grow.