Vector Clocks for Conflict Detection
What You'll Learn
You'll learn how Dynamo uses vector clocks to track the causal history of each value, enabling the system to detect when concurrent writes create conflicts that require resolution.
The Causality Problem
In a distributed key-value store with multiple replicas, the same key can be updated at different nodes simultaneously. Without tracking causal relationships, the system cannot tell whether:
- Update B happened after seeing update A (causally related)
- Updates A and B happened concurrently without knowledge of each other (conflict!)
Simply using timestamps won't work—server clocks drift, and clock synchronization is unreliable across distributed nodes.
How Vector Clocks Work
A vector clock is a list of (node, counter) pairs attached to every value. Each node increments its own counter when writing:
Version 1: [(NodeA, 1)] // Initial write at Node A
Version 2: [(NodeA, 1), (NodeB, 1)] // Node B updates after seeing Version 1
Version 3: [(NodeA, 2), (NodeB, 1)] // Node A updates again (concurrent with Version 2!)
When Dynamo receives a write, it compares vector clocks:
- If one clock's counters are all ≤ another's, it's an ancestor (superseded)
- If neither dominates, they're concurrent—a conflict exists
Conflict Detection in Action
Imagine two users simultaneously updating a shopping cart. The vector clocks [(A,1), (B,2)] and [(A,1), (C,1)] are concurrent because neither dominates. Dynamo keeps both versions and lets the application resolve the conflict (maybe by merging both carts).
Key Takeaway:
Vector clocks track per-node causality counters to detect concurrent, conflicting writes in distributed key-value stores—enabling conflict-aware replication without relying on synchronized clocks.