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
- 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
Recent edits
| Edit | Node | Stamp | What happened |
|---|---|---|---|
| v10 | B | @2158 | kept |
| v9 | A | @1978 | lost: same-time edit dropped |
| v8 | A | @1855 | kept |
| v7 | A | @1705 | kept |
| v6 | C | @1484 | kept |
| v5 | A | @945 | kept |
| v4 | B | @828 | lost: same-time edit dropped |
| v3 | C | @816 | lost: 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
- 2.2sError: B keeps v10 and drops v9 without a word; neither saw the other.
- 1.0sError: C keeps v5 and drops v3 without a word; neither saw the other.
- 1.0sError: A keeps v5 and drops v4 without a word; neither saw the other.
- 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.