Unit 3 of 12 · about 4 hours · derive, implement

Vector clock comparison, concurrency and dotted version vectors

Lamport stamps hide concurrency. Vectors expose it, which is what conflict detection and repair need in later sections.

You'll be able to

  • Compare two vector timestamps and return before, after, equal or concurrent, with the causal-history reading of the result.
  • Run the vector update rules on a message history and explain what entry records about node .
  • State what dotted version vectors change for per-key concurrent writes and when to reach for them.

Covers

Vector clock comparison and concurrencyDotted version vectors
1

Read

In this order, only the parts listed

0 of 2 done

  1. Vector clocks workbookCambridge Concurrent and Distributed Systems Notes (Kleppmann) - Time, Clocks and Ordering

    Section 4.1, Slides 69 to 72: vector algorithm, the worked example where C learns A's two events through B, and the comparison rules; Exercises 12 and 13

    Exercise 13 names three event pairs, send(m2) with send(m3), send(m3) with send(m5) and send(m5) with send(m9). Answer each pair from both the Lamport and the vector columns.

  2. Dotted version vectorsHLD Handbook - Clocks, Failure Detection and Consistent Hashing

    Theory, Dotted version vectors: server-keyed vectors, one dot per value, and the rule for when clients outnumber servers

    Use as review after the notes. It credits server keys with ending sibling explosion; Riak's own account is that server-keyed vectors kept clocks small and the dots fixed sibling explosion. The deployment story is a reported result, not a setup you reproduce here.

2

Focus on

  • On an event at node , increment . On send, attach . On receive, take the element-wise maximum, then increment . Entry counts events of observed so far.
  • A vector stamps a causal history: event plus everything before it. So holds exactly when , equality means the same event, and incomparability means concurrency.
  • The worked example shows indirect knowledge: when C receives from B, its A entry jumps to 2 without ever hearing from A, because B already knew.
  • Dotted version vectors key the vector on servers, not clients, and tag each value with one dot naming the server event that wrote it. A put subsumes the siblings its context observed, so only truly concurrent siblings survive. Server keys keep the vector small; the dots fix the sibling explosion that plain server-keyed vectors cause.
Common mistakes · 3
  • Treating a smaller vector as an earlier event in wall time. The order is causal inclusion, not time, and concurrent vectors are unordered by definition.
  • Merging without the final increment. The receive is a new event at the receiver, and skipping it undercounts the receiver's own entry.
  • Reusing vectors across a membership change. Entries are positional per member, so a join or replacement needs a new epoch or a map keyed by member id, not a silent index shift.
3

Try it yourself

Closed-book, before checking anything

Closed-book, compare with : the first leads in entries 0 and 1, the second in entry 2, so they are concurrent. Then run a receive at process 0 with local and message : the merge is , plus one for the receive, giving .
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Vectors read and . What is their relation, and what does it mean?Answer

    Before: every entry of the first is at most the second's, with entry 1 smaller. The first event happened before the second.

  2. 2.Why does C's A entry become 2 after receiving B's vector, with no message from A?Answer

    B's vector already recorded two A events, and the element-wise maximum copies that knowledge. Vectors carry transitive history, not just direct contact.

  3. 3.Two replicas hold dots and for one key with incomparable contexts. Siblings or overwrite?Answer

    Siblings. Neither context subsumes the other, so the writes are concurrent and both values stay until something resolves them.

  4. 4.What breaks if you compare vectors stamped under different member sets?Answer

    Positions no longer name the same members, so before, after and concurrent verdicts are meaningless. Re-key or re-epoch on membership change.

5

Practice

  • Compare Two Vector Clocks

    Implement compare: before when every entry of a is at most b's with one smaller, after for the reverse, equal for identical, else concurrent

    Write the four-way rule from memory first, then add your own tests for equal vectors and for vectors that tie in every entry but one.

  • Update a Vector Clock on Receive

    Implement update: element-wise maximum of local and received, then add 1 at index; the first example merges [1,0,0] and [0,1,0] at process 0 into [2,1,0]

    Do not modify the inputs. Extend to dotted versions in the section mini-project, where keys carry dots.

You're done when

You return the reproduce comparison and merge without notes, and both problems pass with the rules stated from memory.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 12 more in the section

Also in this section

  • DDIA 2e - Chapter 9 The Trouble with Distributed SystemsMartin Kleppmann and Chris Riccomini · primary

    Read clocks, pauses, unreliable networks, partial failures and knowledge limits. For each failure, record what a node observes, what is true globally and what action is safe under that uncertainty.

  • Time, Clocks, and the Ordering of Events in a Distributed System (Lamport, 1978)Leslie Lamport · required

    Read the partial ordering and logical clocks sections: happens-before, the Clock Condition, rules IR1 and IR2, and the total order. Its ties are broken arbitrarily, so the total order is not causality.

  • Logical Physical Clocks and Consistent Snapshots (Kulkarni et al., 2014)University at Buffalo · support

    Read the hybrid logical clock algorithm and its bounds; the paper reports the logical counter staying well below its proved bound in practice, so measure your own.

  • SWIM: Scalable Weakly-consistent Infection-style Process Group Membership (Das et al., 2002)Cornell University · support

    Read the direct and indirect probing detector, infection-style dissemination, the suspicion mechanism and incarnation numbers. Suspicion timeouts depend on the workload.

  • The phi Accrual Failure Detector (Hayashibara et al., 2004)JAIST · support

    Read how phi is computed from the heartbeat inter-arrival history and how a threshold trades detection time for false suspicion. Its normal approximation misleads under bursty delay, so test with pause traces too.

  • How to Do Distributed Locking (Kleppmann, 2016)Martin Kleppmann · required

    Read the process-pause, network-delay and fencing-token sections with DDIA 2e Chapter 9 "Distributed Locks and Leases". Treat the Redlock critique as dated to 2016; the lasting lesson is that the storage service must reject a write that carries an older token.

  • Building Distributed Systems - The TimekeeperBuild Distributed Systems · optional

    Only the first three tasks are free (clock reads and backward jumps, a monotonic wrapper, a split-brain lease). Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.

  • Building Distributed Systems - The GossiperBuild Distributed Systems · optional

    Only the first three tasks are free (basic broadcast, tree topology, random gossip). Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.

  • Gossip Glomers - Unique IDs and BroadcastFly.io and Jepsen · required

    Each challenge runs locally under Maelstrom (v0.2.4; the pages were tested on 0.2.3) with its checker and, where the page says so, the partition nemesis; keep the run directory as the history. Do challenge 2 (unique IDs under partition with total availability) and 3a to 3c (broadcast, then with partitions). A pass shows uniqueness or convergence in that run, not ordering or recency.

  • MIT 6.5840 - Failure and Paper Discussion LensMIT PDOS · support

    Use the RPC, GFS, Raft and consistency lectures to identify which timing assumptions affect progress and which invariants must not depend on time. Do not start the Raft lab yet.

  • Replicated Log and Stream Processor - Time and Membership SliceRoadmap-Final · support

    Add incarnation IDs, logical timestamps, gossip membership, suspicion metrics and fenced ownership. Retain seeds and minimized traces for every false-failure or stale-actor case.

  • AlgoMaster System Design practice - clock, gossip and lease drillsAlgoMaster · support

    Use only the named problems: Advance a Lamport Logical Clock, Compare Two Vector Clocks, Update a Vector Clock on Receive, Advance a Hybrid Logical Clock, Simulate Gossip Rumor Spread and Implement a Lease Lock with Fencing Tokens. Each states its function signature and checks small deterministic cases.