Conflict Resolution Strategies
Conflict Resolution Strategies
Last Write Wins (LWW)
Used by: Cassandra, DynamoDB (default mode)
Compare timestamps. Highest wins. Discard the other.
India currently has: name = "shi" (t=110)
Late entry arriving: name = "hat" (t=101)
t=110 > t=101 → keep "shi", discard "hat"Result: both nodes converge to "shi". "hat" is gone — permanently and silently. This is silent data loss. It is an accepted tradeoff.
Vector Clocks + Conflict Surfacing
Used by: DynamoDB (advanced mode), Riak
Instead of discarding, track which writes knew about which other writes.
The system does not pick a winner. It stores both and returns both:
read("name") → ["shi", "hat"] ← your application must decideNo data is lost. But your application must handle the conflict — merge them, pick one, or show both to the user.
Synchronous quorum (see Synchronous consensus) sidesteps this entirely: if you chose Option 1, only one write is ever committed at a time — the second is blocked until the first is agreed on. The late-entry scenario in this part cannot occur. The cost, as before, is paying ~200ms per write for cross-region agreement.
The Core Distinction: Log vs. State
The log records events. The database state is derived by applying those events. When a late entry arrives, the log gets a new entry appended at the end — the database does not go back in time. The conflict resolution strategy decides what that new entry does to the current state: overwrite it (LWW) or surface it as a conflict (vector clocks).
What "Eventually Consistent" Actually Means
The guarantee is narrow: if all writes stop, all nodes will eventually agree on the same value. It does not guarantee when. It does not prevent stale reads during the convergence window. A user reading from India and a user reading from US can see different values at the same time — this is expected behavior, not a bug.
Where Do You Pay?
| Approach | Write speed | Conflict risk | Data loss risk | Complexity |
|---|---|---|---|---|
| Synchronous (Spanner, CockroachDB) | Slow (~200ms) | None | None | Low |
| Async + LWW (Cassandra, DynamoDB) | Fast (local) | Yes | Yes (silent) | Low |
| Async + Vector Clocks (Riak) | Fast (local) | Yes | None | High (app handles conflicts) |
The choice: do you pay at write time (latency) or at conflict time (complexity / data loss)?