Scrivio Interview library
ConceptFoundations6 min read · updated 13 November 2026

Last write wins (LWW) is the simplest conflict rule in replicated stores: every write carries a timestamp, and when replicas disagree the value with the highest timestamp is kept.

How does LWW work in a store such as Cassandra, what does it lose without any error, and for which kinds of data is it acceptable?

With last write wins, every cell stores a write timestamp, normally in microseconds from the coordinator or the client, and whenever replicas disagree, on reads or during compaction, the value with the highest timestamp is kept, with a deterministic tie-break. Concurrent writes are never merged, so one of two near-simultaneous updates disappears without any error, and clock skew makes it worse: a writer whose clock runs ahead beats later writes, and a delete with an older timestamp cannot remove a value. LWW is acceptable for immutable or write-once data, single-writer overwrites, caches and last-known state, but not for counters, shared collections or anything where a lost update costs money.

Why this question is asked

Last write wins is the default conflict rule in Cassandra and many other replicated stores, so most engineers use it without choosing it. Interviewers ask about it to see whether we know what it silently throws away and can tell data that tolerates it from data that does not. In this answer, we will see how LWW works at the level of cells and timestamps, reproduce a lost update, look at how clock skew makes things worse, and then sort data into what is safe and what is not, with the alternatives.

1How LWW Works in Cassandra

Cassandra stores data as cells, one per column value, and every cell carries a write timestamp in microseconds. By default the coordinator assigns it when it receives the write, and most drivers can assign it on the client instead; a query can also set it explicitly with USING TIMESTAMP. Replicas do not coordinate when they store a write. When a read finds different versions of a cell on different replicas, or when compaction merges files holding different versions, the version with the highest timestamp wins and the others are discarded.

If two versions have exactly the same timestamp, the result must still be the same on every replica, so there is a deterministic tie-break: a deletion wins over a value, and between two values the larger one by byte comparison wins. Check your version for the precise rules. Notice that resolution happens per cell, not per row: two clients updating different columns of the same row do not conflict.

2Reproducing a Lost Update

Two support agents edit the same customer's notes at nearly the same moment. Each reads the current text, adds a line, and writes the whole value back.

SQL
-- both agents read: notes = 'VIP'
-- agent 1, timestamp 1731510000000100
UPDATE customers SET notes = 'VIP; refund issued' WHERE id = 42;
-- agent 2, timestamp 1731510000000250, 150 microseconds later
UPDATE customers SET notes = 'VIP; address changed' WHERE id = 42;
SELECT notes FROM customers WHERE id = 42;
-- 'VIP; address changed' the refund note is gone, and nobody was told
Step throughTwo concurrent writes resolved by timestamp
Agent 1Agent 2Replica AReplica B
notes = refund (ts ...100)
notes = address (ts ...250)
repair or read: compare cells
ts ...250 is higher
keep address, drop refund

5 messages in order. Play them, or step through them one at a time.

Neither write failed; one was discarded during resolution.

Both writes succeeded, both agents were told so, and one write simply vanished when the replicas resolved the conflict. LWW never merges; it picks. Notice also that the outcome would be the same even if agent 1 wrote last in real time, provided agent 2's timestamp was higher, which brings us to clocks.

3Clock Skew Makes It Worse

Timestamps come from clocks on different machines, and those clocks are never perfectly aligned. If a client's or coordinator's clock runs 200 milliseconds ahead, its writes beat any write made by others within the next 200 milliseconds of real time. A write that really happened later loses, silently.

Deletes suffer in the same way. A delete writes a tombstone with a timestamp; if that timestamp is older than the existing value's, because the deleting machine's clock is behind, the tombstone loses and the value stays. Users see a record they deleted come back, or never go away. Keeping clocks synchronised with NTP or chrony reduces the window, but it cannot remove it, because concurrent writes within the remaining skew are still decided by the clocks, not by real order.

4When LWW Is Acceptable

LWW is fine whenever losing a concurrent write cannot happen or does not matter. Immutable or write-once data, such as events, logs or uploaded files keyed by a unique id, never has two writes to the same cell. Idempotent overwrites from a single writer, such as one service owning a record and replaying the same value on retry, produce no real conflicts either. Caches can always be refilled from their source. And last-known-state data, such as a device's most recent position or a sensor's latest reading, wants exactly the newest value, and an occasional lost intermediate value is harmless.

LWW is not acceptable for counters, where two increments that both read 5 and write 6 lose one increment, for collections edited by several users, such as a shared list rewritten as a whole, or for anything where a lost update costs money, such as balances, inventory or bookings.

Is last write wins acceptable?
DataSafe with LWW?Why or what instead
Event or log keyed by unique idyeswrite-once: no second write to conflict
Device's latest positionyesnewest value wanted; lost intermediates harmless
Cache entryyescan be rebuilt from the source
Counternolost increments; use counters, CRDTs or aggregation
Shared tag listnoper-element cells (set column) or an OR-Set
Account balance or stocknoconditional writes, single writer or a transactional DB

5Alternatives When Updates Must Not Be Lost

Several techniques avoid lost updates without abandoning the store. Per-field cells shrink conflicts: storing each note as its own entry in a map or set column means two agents adding different notes write different cells, and both survive. Conditional writes, Cassandra's lightweight transactions such as UPDATE ... IF version = 7, turn a conflict into a visible failure that the client can retry. CRDTs, data types designed to merge concurrent updates, keep both changes for counters and sets. And a single writer per record, for example routing all updates of a customer through one service instance or partition of a queue, removes concurrency altogether.

6Follow-up questions

Can we avoid clock problems by using client-side timestamps?

Client timestamps let one client order its own writes reliably, but different clients still have different clocks, so cross-client conflicts are still decided by skew. They also let a client with a wrong clock override everyone. Server-side timestamps with synchronised clocks are usually safer.

Does LWW lose data in a single-replica setup?

The conflict rule only applies between versions of a cell, but a read-modify-write sequence by two clients loses an update even on one replica. LWW is just the rule that makes this silent in a replicated store.

Why does a delete wins on a timestamp tie?

So the outcome is identical on every replica regardless of the order in which they saw the two writes. Any deterministic rule would do; deletion winning is the conservative choice.

7Conclusion

In this answer, we saw that last write wins keeps, per cell, the version with the highest timestamp, with a deterministic tie-break. It never merges concurrent writes, so one disappears without an error, and clock skew lets a later write lose and an older-stamped delete fail. LWW suits write-once data, single-writer overwrites, caches and last-known state, and is wrong for counters, shared collections and money; per-field cells, conditional writes, CRDTs or a single writer avoid the losses.

What to say in the interviewAbout 100 seconds aloud

Open with

In Cassandra every cell carries a write timestamp in microseconds, set by the coordinator by default or by the client. Replicas never coordinate on writes, so whenever they hold different versions of a cell, during a read or a compaction, the highest timestamp wins, and on an exact tie there is a deterministic rule, deletes first, then the larger value, so all replicas agree.

Then, if they want more

What it loses silently is concurrent writes. If two agents read the same notes and each writes back their own addition a fraction of a second apart, both get success, and one addition disappears; LWW picks, it never merges. Clock skew makes it worse.

A machine whose clock runs ahead beats writes that really happened later, and a delete stamped with an older time than the value cannot remove it, so deleted data stays or reappears. NTP narrows the window but cannot close it.

So I use LWW where a lost concurrent write cannot happen or does not matter: write-once data like events keyed by unique ids, idempotent overwrites from a single writer, caches, and last-known-state data like a device's latest location.

I do not use it for counters, collections several users edit, or anything where a lost update costs money, like balances or bookings. There I would use per-field cells such as set or map columns, conditional writes with lightweight transactions, CRDTs, or route all writes for a record through a single writer.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How does LWW work in a store such as Cassandra, what does it lose without any error, and...": https://scrivio-interview-library.netlify.app/architecture/partitioning-and-replication/30bcd64b8c/