Course contentsShow
← System Design
Lesson 368 of 1,91910. NoSQL: Key-Value StoresFree lesson

Conflict Resolution Strategies

Techniques for resolving conflicting versions including last-write-wins and application-level merging.

Conflict Resolution Strategies

What you'll learn: How distributed key-value stores decide which version of conflicting data to keep when multiple writes occur.

The Conflict Problem

In distributed key-value stores with eventual consistency, two nodes might accept different writes to the same key simultaneously. When they sync, both versions are valid from each node's perspective. Vector clocks detect this conflict, but something must decide which value wins or how to merge them.

Last-Write-Wins (LWW)

The simplest strategy: use timestamps to pick the most recent write. The version with the latest timestamp becomes the "truth," and the other is discarded.

Analogy: Two people edit a shared document offline. When they reconnect, you just keep whichever version has the newer "last modified" date.

Tradeoffs:

  • Simple and automatic
  • Permanent data loss for the discarded write
  • Clock skew between nodes can cause incorrect ordering
  • Best for data where losing an update is acceptable (counters, caches)

Application-Level Merging

Instead of automatically discarding data, the system returns all conflicting versions to the application. Your code decides how to merge them intelligently.

Analogy: Like a shopping cart where two devices add different items offline. When syncing, you merge both carts instead of picking one.

Tradeoffs:

  • No automatic data loss
  • Application complexity increases
  • Requires custom merge logic per data type
  • Best for critical data like user preferences, shopping carts, or collaborative editing

Choosing a Strategy

Use last-write-wins for disposable or easily-regenerated data where simplicity matters. Use application-level merging when every write is valuable and your application understands the data's semantics well enough to merge intelligently.

Key Takeaway: Conflict resolution trades simplicity (last-write-wins) against data preservation (application-level merging)—choose based on whether losing updates is acceptable for your use case.