Sweaty Imposter

Vector Clocks / Version Vectors

TechniqueDistributed SystemsSeniorStaffUpdated
Each replica tags writes with a per-node counter map. Comparing two versions reveals causal order, concurrency, or strict dominance.

When to Use Vector Clocks / Version Vectors

Leaderless replication where multiple writers may touch the same key. Lets the system detect siblings (concurrent versions) instead of silently dropping one.

In Practice

Amazon Dynamo (the 2007 paper), Riak, and Voldemort use version vectors. Cassandra skipped them and uses last-write-wins timestamps instead, which is simpler but lossy.

Sketch

Python

# Compare two vector clocks
def compare(a, b):
    a_dominates = all(a.get(n, 0) >= b.get(n, 0) for n in a | b)
    b_dominates = all(b.get(n, 0) >= a.get(n, 0) for n in a | b)
    if a_dominates and b_dominates: return "equal"
    if a_dominates: return "a_after_b"
    if b_dominates: return "b_after_a"
    return "concurrent"  # siblings, app must merge

How Vector Clocks / Version Vectors Comes Up in Interviews

Scenario

Two clients write to the same Cassandra row from different coordinators within milliseconds. How does Cassandra resolve the conflict on read?

Cassandra actually uses last-write-wins by cell timestamp, but the broader question of 'detect concurrent writes between replicas' is what version vectors / vector clocks are for. Riak and Dynamo use them to surface siblings the app must merge.

Cassandra's LWW is simpler but silently drops one write if clocks skew. Riak's vector clocks preserve both versions and force the client to merge, which is the safer default for multi-writer workloads.