Unit 5 of 12 · about 4 hours · explain, implement
Unique identifiers, incarnation numbers and restart-safe identity
Every dedup key, fencing check and membership entry names an actor. A reused identity turns an ordinary restart into a split brain.
You'll be able to
- Choose an ID scheme, random, wall-clock-ordered or Lamport pair, and state its collision, ordering and coordination costs.
- Assign incarnation numbers so a restarted process never reuses a live identity, and say who may increment them.
- Persist the identity state that makes restart safe, and test the dual-incarnation case.
Covers
Read
In this order, only the parts listed
0 of 3 done
- ID generators and Lamport pairsDDIA 2e - Chapter 9 The Trouble with Distributed Systems
Chapter 10, ID Generators and Logical Clocks: autoincrement and linearizable single-node IDs, random UUIDs and wall-clock timestamp schemes (pp. 417-419); Lamport (counter, node ID) pairs with the Aaliyah, Bryce and Caleb ordering and Figure 10-9 (pp. 420-421)
- Incarnation numbers against false suspicionSWIM: Scalable Weakly-consistent Infection-style Process Group Membership (Das et al., 2002)
Section 4.2, Suspicion Mechanism: incarnation initialized at join, incremented only by the suspected node itself; Alive refutes older Suspect, but Confirm overrides Alive and Suspect at any incarnation
- Unique IDs under partitionGossip Glomers - Unique IDs and Broadcast
Challenge 2:
generatewith any ID type under partition with total availability; run./maelstrom test -w unique-ids --bin ~/go/bin/maelstrom-unique-ids --time-limit 30 --rate 1000 --node-count 3 --availability total --nemesis partitionwith the binary path pointed at your own node; uniqueness is checked, ordering and monotonicity are not
Focus on
- Single-node autoincrement is linearizable: an insert that completes before another begins gets the smaller ID. No distributed scheme in this unit keeps that without coordination.
- Random 128-bit IDs need no communication and give no order. Wall-clock schemes sort roughly but lean on NTP, a shard or random part, and a per-shard sequence for same-millisecond uniqueness.
- A Lamport pair is unique when node IDs are unique, and orders causally but not by wall time. Two nodes that never communicate can hold wildly different counters.
- Only the suspected member increments its SWIM incarnation; a higher Alive refutes older Suspect, but the original paper's Confirm is terminal for that member identity. Separately, persist an ID epoch before using it and advance it durably on restart, so new IDs cannot collide with pre-crash IDs.
Common mistakes · 3
- Reading wall-clock ID order as causal order. A fast clock stamps an earlier write above a later one from a slow clock, and one NTP step reorders a single node's IDs.
- Letting another node bump a member's incarnation. Only the member itself increments; anything else lets a node that never heard from the member refute its suspicion.
- Rejoining with the same identity and a reset counter. The group still holds the old incarnation, so rejoin as a new epoch or a new member, never as a silent reset.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.A billion random version-4 IDs are generated. About how likely is one collision?Answer
About . With 122 random bits the birthday term is near , vanishingly small but not zero, and it says nothing about order.
2.Two Snowflake IDs sort correctly. Does the earlier-sorting record causally precede the other?Answer
Not proven. Sort order follows wall clocks plus shard and sequence parts; skew or a step can invert it relative to causality.
3.Node X is suspected at incarnation 3, then broadcasts Alive at incarnation 4. A late Suspect for incarnation 3 arrives after. What does the group keep?Answer
Alive at 4. The higher incarnation wins, and the stale report for 3 is dropped.
4.Why must the epoch live on stable storage rather than in memory?Answer
Memory resets on crash, which replays epoch 1. Stable storage survives, so the next boot provably moves to epoch 2.
Practice
- Gossip Glomers 2: Unique ID Generation
Run
./maelstrom test -w unique-ids --bin ~/go/bin/maelstrom-unique-ids --time-limit 30 --rate 1000 --node-count 3 --availability total --nemesis partitionwith the binary path pointed at your node; keep the run directoryMaelstrom runs local processes over a simulated network, but this challenge does not test restart. The section mini-project covers this: issue IDs, restart with the same durable state, issue more, and check uniqueness across both batches.
You're done when
The challenge passes, your separate restart test has no duplicate across both batches, and you can name the durable state that prevents reuse.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 11 more in the 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.
- 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.
- 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.
Also in this section
- 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.
- 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.
- Cambridge Concurrent and Distributed Systems Notes (Kleppmann) - Time, Clocks and OrderingUniversity of Cambridge (Martin Kleppmann) · support
Use Chapter 3 (physical clocks, NTP and monotonic clocks, happens-before) and Section 4.1 (Lamport and vector clocks with worked examples) as the derivation workbook: work Exercises 7 to 13. Each section marks where its public lecture video starts.
- 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.
- HLD Handbook - Clocks, Failure Detection and Consistent HashingHLD Handbook · required
Read Part 3 clocks and ordering, failure detection and consistent hashing. Use its exercises to compare assumptions, then verify claims against your own histories.
- 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.