Course contentsShow
← Software Engineering
Lesson 924 of 1,93328. Transactions and ConsistencyFree lesson

Conflict Resolution Strategies

Explore techniques like last-write-wins, vector clocks, and CRDTs for resolving conflicts in eventually consistent systems.

Conflict Resolution Strategies

You'll learn: How eventually consistent systems decide which version of conflicting data "wins" when multiple writers update the same record independently.

In distributed systems with eventual consistency, network partitions or concurrent updates can create conflicting versions of the same data. Unlike strongly consistent systems that prevent conflicts through locks, eventually consistent systems accept that conflicts will happen and need strategies to resolve them gracefully.

Last-Write-Wins (LWW)

The simplest approach: use timestamps to decide which update is newest. When two versions conflict, keep the one with the later timestamp and discard the other.

Analogy: Two people edit a shared document offline. When they reconnect, you simply keep whichever version was saved most recently.

Downside: Clock skew between servers can make timestamps unreliable, and you permanently lose the "losing" update—even if it contained valuable changes.

Vector Clocks

Each replica maintains counters tracking which updates it has seen from every other replica. When versions conflict, vector clocks reveal causal relationships: whether one version happened-after another, or if they're truly concurrent and conflicting.

Analogy: Instead of one timestamp, each document version carries a logbook showing "I've seen 3 edits from Alice, 5 from Bob, 2 from Charlie." You can tell if versions are related or independent.

Downside: Metadata grows with the number of replicas, and applications must still decide how to merge truly concurrent updates.

CRDTs (Conflict-Free Replicated Data Types)

Mathematical data structures designed so merging any two versions is deterministic and always produces the same result. Common examples: grow-only sets, counters that only increment, or registers that merge based on rules.

Analogy: A shared shopping list where everyone can only add items. Merging two versions means taking the union—no conflicts possible.

Key Takeaway: Eventual consistency requires choosing conflict resolution strategies that match your business requirements—whether sacrificing updates (LWW), tracking causality (vector clocks), or using specially-designed data structures (CRDTs).