skip to content

Conflict Resolution

When two replicas accept conflicting writes, something has to reconcile them: last-write-wins, vector clocks, version vectors, or handing the conflict to the application. You will learn what each strategy silently loses, which is why LWW is more dangerous than it looks.

part ofDistributed & scalable systemsread it →
on this pageshow

questions

6

In an eventually consistent data store, two replicas each accept a write to the same key while a network partition separates them. When the partition heals and the store uses last-write-wins (LWW) to reconcile, what happens to the value, and what has to happen for that to work reliably?

level: juniorimportance: must knowfreq 75%

answer

  1. timestamp wins
  2. clock skew -> silent loss
  3. no merge, no notify
  4. per-column vs per-row granularity
  5. HLC: causal order, not concurrency

basics

~20 s

Last-write-wins keeps whichever write carries the larger timestamp and throws the other away. For that to work, every write needs a timestamp, and the clocks stamping them must be close enough to compare across machines.

solid answer

~50 s

LWW resolves conflicting writes by attaching a timestamp to every write and, when replicas reconcile after a partition heals, keeping the one with the larger timestamp (a node or replica id can break exact ties). It's attractive because it needs no application logic and no metadata beyond that timestamp. The catch is that 'reliably' hides a hard requirement: the timestamps have to be comparable across nodes, so clocks need to be kept synchronized (NTP). If clocks drift, a write that happened later in real time can lose to an earlier one just because its node's clock was behind. A hybrid logical clock fixes part of this: a write that follows another through the system's messages always gets the larger timestamp, but two truly concurrent writes are still ordered by their clocks. And LWW silently discards the losing write entirely: fine for a 'last seen' field, dangerous for a shopping cart.

go deeper

for a junior

Should be able to state that LWW keeps the value with the larger timestamp, that every write needs a timestamp to compare, and that the other write is lost with no error raised.

for a middle

Should know that comparability requires synchronized clocks, name a scenario where a causally later write loses because its node's clock is behind, and explain the deterministic tie-breaker (a node id) that makes every replica choose alike.

for a senior

Should reason about whole-row versus per-column comparison, say what a hybrid logical clock fixes for LWW and what it leaves (concurrent writes), and name a real store that resolves by LWW and at what granularity.

for a principal

Should be able to set organization-wide guidance on when LWW is an acceptable default vs when it requires an explicit risk sign-off, and design monitoring to detect silent loss at scale.

## How LWW picks a winner Last-write-wins (**LWW**) is the simplest conflict-resolution strategy an eventually consistent store can use: when two replicas hold different values for the same key because they each accepted a write while the other was unreachable, the store compares a timestamp attached to each write and keeps the value with the larger timestamp, discarding the other entirely. The timestamp is written client-side or coordinator-side at write time — either: - a raw **wall-clock reading**, - or a **hybrid logical clock (HLC)**, which keeps each timestamp within the clock-synchronization bound of the physical clock but never stamps an event lower than an event that reached it, through the system's messages, before it. Some systems also carry a replica or node id as a final tie-breaker when timestamps are exactly equal, so the outcome is deterministic no matter which replica performs the comparison. Once the partition heals and replicas exchange their versions (via anti-entropy, read-repair, or hinted handoff), each replica runs the same comparison and converges on the same winner — that determinism is what makes LWW usable in a leaderless, multi-master system with no coordinator to arbitrate. ## Why it exists LWW exists because the other ways to settle a conflict ask for more: - a **central authority** to serialize writes (which sacrifices availability during partitions, the thing eventual consistency is trying to preserve), - or **merge logic**: application code that understands how to combine two divergent values, or a data type built to merge (a CRDT), either of which is extra engineering for every field. LWW sidesteps both: it needs no consensus round and no merge, just a comparable timestamp already present on the write. That makes it **Cassandra**'s conflict model (a timestamp on every column, the larger one wins) and one selectable policy in **Riak**, whose newly created bucket types keep concurrent versions as siblings by default instead. It's attractive whenever the 'right' answer really is 'whichever write happened most recently,' such as a user's last-known IP address or a cache entry. ## The trade-off The trade-off is that LWW buys simplicity by being willing to lose data. The losing write isn't merged, queued for review, or even logged by default — it simply vanishes, and neither client that made the concurrent writes is told anything happened. This is acceptable for values where only the latest state matters, but it is the wrong tool whenever a write represents an operation rather than a value replacement — two concurrent 'add item to cart' writes are not readings of the same underlying fact, and picking one over the other silently drops a customer's item. ## Failure modes 1. **Clock-skew-induced causality violation** — the first failure mode. Because LWW orders writes by timestamp rather than by actual happened-before relationships, a write that is causally later (a client saw the first write's result and then issued a follow-up) can still lose if its node's physical clock lags behind the other node's. A concrete pattern: a user updates their profile, the update briefly appears, then an earlier write, accepted by a node whose clock runs ahead, carries the larger timestamp, 'wins' during reconciliation, and the user's change disappears — without any error being raised, which makes it a support-ticket generator rather than something caught in testing. 2. **Whole-value comparison** — a second failure mode, about the unit LWW compares rather than the clock. An implementation that timestamps whole values or whole rows rather than individual fields lets an update to field A on one replica wholly overwrite a concurrent update to field B on another replica, even though the two changes don't logically conflict at all. (Two writes that land in the same clock tick are a separate matter: they tie, and the node-id tie-breaker decides.) ## Cassandra in practice Cassandra resolves conflicts this way. Every write is timestamped, from the client's clock or, absent a client-provided timestamp, from the coordinator node's clock, and Cassandra keeps a separate timestamp for every column of every row, so each column settles concurrent writes by last write wins on its own. Concurrent updates to different columns of one row therefore both survive, which avoids the whole-row clobber; two concurrent writes to the same column still lose one. Its documentation states that Cassandra's correctness depends on these clocks and asks for a time-synchronization process such as NTP to be running. Teams that need correctness guarantees stronger than 'usually right, occasionally silently wrong' either: - pair LWW with hybrid logical clocks, so a write that follows another through the system's messages always carries the larger timestamp (concurrent writes are still settled by their clocks, and one of them is still lost), - or move the field to a strategy that preserves both writes (vector clocks plus application merge) instead of discarding one.

  • What is a hybrid logical clock and why do systems prefer it over raw wall-clock timestamps for LWW?
    A hybrid logical clock (HLC) pairs a physical clock reading with a logical counter. Each event sets it to at least the node's physical clock and above every timestamp received, so if A happened before B through messages carrying the clock, A's timestamp is smaller, which skewed wall clocks cannot promise, while it stays within the synchronization bound of physical time. For LWW, a write whose node has seen the other's timestamp no longer loses to it; concurrent writes are still ordered by clocks.
  • If LWW is risky, why does a widely used store like Cassandra build its conflict model on it?
    Because it needs no causality metadata and no reconciliation by clients: any replica settles a conflict on its own by comparing timestamps. Cassandra narrows the damage by timestamping each column separately, so concurrent writes to different columns of a row both survive, and its documentation says its correctness depends on synchronized clocks. What it gives up is one of two concurrent writes to the same column, so it suits data where the latest value is the right one.
  • How would you detect that LWW is silently dropping writes in production?
    Track write and read metrics per key alongside comparing values you expect against actual stored state, or instrument the reconciliation path to log or count every time a write is discarded by a timestamp comparison. Sampling discarded writes into an audit log and replaying them shows how often causally later writes lose. Without this instrumentation, LWW data loss is invisible because there's no error path, only a quietly different final value.

Like two people editing a shared whiteboard from different rooms with clocks that aren't perfectly synced — whoever's watch says the later time gets to keep their writing, even if the other person actually wrote second in real life.

  • Says LWW never loses data as long as timestamps exist
  • Assumes wall-clock timestamps are always causally ordered
  • Doesn't know LWW requires clock synchronization to be meaningful
  • Applies LWW to counters/collections instead of last-value fields
  • Thinks the losing write is logged or recoverable by default

context

open as a page

A distributed key-value store attaches a vector clock to every value it stores, one counter per replica. When two versions of the same key are compared during a read, how does the store use the vector clocks to decide whether one version happened-before the other, or whether the two are concurrent and represent a real conflict?

level: middleimportance: must knowfreq 70%

basics

~20 s

A vector clock is a list of counters, one per replica, attached to a value. Comparing two versions' lists shows whether one grew out of the other or both were written independently, though two clients' writes through one replica look ordered.

open as a page

When automatic conflict resolution (like LWW or vector-clock causality checks) cannot safely pick a winner because two writes are truly concurrent and semantically different, systems like Amazon's Dynamo return both versions to the application as 'siblings.' Concretely, how does an application perform a semantic merge on such siblings, using a shopping-cart example, and what does the application have to guarantee for the merge to be safe?

level: seniorimportance: must knowfreq 65%

basics

~20 s

When a database can't safely decide which of two conflicting writes is 'right,' it hands both versions to the application, whose code knows what the data means and merges them, like combining two shopping carts instead of losing one cart's items.

open as a page

Last-write-wins is popular because it's simple and requires no application involvement. Walk through at least three concrete ways LWW can silently lose committed data or violate causality in production, and describe one situation where you would deliberately choose LWW anyway despite these risks.

level: seniorimportance: must knowfreq 60%

basics

~20 s

Last-write-wins can quietly throw away real changes when clocks disagree, when a whole record gets overwritten instead of just the changed part, or when a 'delete' loses to an older 'update.' It's still fine to use when only the newest value ever matters, like a cache or a heartbeat.

open as a page

A team building a Dynamo-style store advertises 'vector clocks' for conflict detection, but a reviewer says what they've actually implemented is a version vector, and that the distinction matters for correctness. What is the difference between a vector clock and a version vector in this context, and what unbounded-growth problem do both share in a system with many nodes or clients?

level: middleimportance: should knowfreq 40%

basics

~20 s

A vector clock counts every event of every process; a version vector counts only updates to stored data. Correctness turns on who gets entries: per server, concurrent writes through one server can overwrite each other; per client, it grows with clients.

open as a page

In a leaderless replicated store using vector-clock-based conflict detection, deletes are often implemented as tombstone writes rather than physically removing data. Explain why plain deletes are dangerous under concurrent conflict resolution, and what problems tombstones introduce over time that operators must manage.

level: principalimportance: should knowfreq 35%

basics

~20 s

If a deleted record is just erased, a replica that missed the delete can send its old copy back, and the record reappears. So stores keep a 'deleted' marker, a tombstone, for a grace period, then purge it to save space.

open as a page