Distributed Systems
Clocks: build a conflict-detecting store
Reading that last-write-wins drops data on a skewed clock is not the same as watching it happen and then making it stop. Build a tiny replicated key-value store, inject clock skew, reproduce the silent loss, then swap in vector clocks and prove that concurrent writes survive as siblings instead of one of them vanishing.
Turn the unit’s mental model into running code: reproduce silent data loss from clock skew under LWW, implement happens-before comparison with vector clocks, detect concurrency, and demonstrate that no concurrent write is ever silently dropped.
Build a small in-memory replicated KV store with two conflict-resolution strategies — wall-clock last-write-wins and vector clocks — reproduce silent data loss under LWW with a skewed clock, then show vector clocks detect the concurrent writes and keep both as siblings.
- A reproducible demo script that, under LWW with the injected skew, prints the dropped write and the success ack — the silent-data-loss signature.
- The same script under vector clocks prints 'concurrent' for the two writes and returns both siblings, with no write silently dropped.
- Tests pass showing happens-before pairs collapse to a single version and concurrent pairs surface as siblings.
- A one-paragraph write-up explaining why LWW lost the write (highest timestamp belongs to the fastest clock, not the latest write) and why vector clocks did not (they compare causally, not by physical time).
- Measure the metadata cost: log vector size as you scale from 3 to 50 nodes, then implement pruning (cap entries, or dotted version vectors) and show siblings are still correctly detected with bounded metadata.
- Add a far-future tombstone: delete K with a timestamp an hour ahead under LWW and show it suppresses every later real write; then show the vector-clock store treats the delete as just another concurrent version.
- Add a Lamport-clock strategy as a third option and demonstrate the gap: it gives a clean total order but silently picks a winner for the concurrent pair (no siblings), sitting between LWW and vector clocks.
- Sketch (or implement a mock of) a TrueTime-style commit-wait path: assign a commit timestamp, sleep out a configurable ε, and argue what external consistency would buy you here versus the vector-clock approach.
This is the loop behind every real conflict-resolution decision: reproduce the failure (LWW silently drops the newer write because the highest timestamp belongs to the fastest clock), then fix it with the right primitive (vector clocks compare causally, detect concurrency, and keep siblings instead of guessing). Building it once — skew injection, happens-before comparison, sibling surfacing, and the metadata cost you pay for detection — turns the unit’s mental model into instinct you can reach for when a production store starts losing writes.