0

In the book Designing Data-Intensive Applications > chapter-5 > Leaderless replication > Detecting Concurrent Writes, below is what Author says while talking about Last write wins (LWW)

The only safe way of using a database with LWW is to ensure that a key is only written once and thereafter treated as immutable, thus avoiding any concurrent updates to the same key. For example, a recommended way of using Cassandra is to use a UUID as the key, thus giving each write operation a unique key

If keys are immutable, why do I even need LWW? Am I missing something here?

1
  • <opinion>LWW sounds like a stupid way to design a database.</opinion>. Most modern RDBMs have "transactions" to deal with "simultaneous" writes. That usually involves "rolling back" one of the competing clients. I have used databases for over 30 years; I have never heard of LWW. Commented May 12 at 21:39

1 Answer 1

0

I believe you are understanding this in a wrong sense.

You do not

Need LWW if keys are immutable.

You should

Use keys that are immutable if DB is of type LWW.

The pre-condition here is not that "keys are immutable". Precondition is "DB is LWW"; and conclusion is not "Need LWW". Conclusion is "given pre-condition DB is LWW, you need to make keys immutable"

Sign up to request clarification or add additional context in comments.

4 Comments

Please correct, why would I need LWW either way? if keys are immutable then technically there shouldn't be any conflicts. Hence no need for LWW conflict resolution? Thank you
Keys are not immutable by default. Keys being immutable is a guideline you follow to make the best of an LWW db. You "might" as well have no immutable keys and an LWW db, if that suits ur purpose. Immutable keys is just a suggestion for strongest consistency.
I think I get your point. Would you say if I use UUID as the key, does it makes any sense to use LWW (or any particular usecase)?
Nope, it does not make sense for the particular case. However, the choice you have is about making UUID as the key and not about having LWW database. However, I can suggest an example where even mutable keys make sense with LWW database. Say, a counter whose only work is to add one to the db.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.