Version Vector(III)
Pratik Pandey
Senior Software Engineer at Booking.com | AWS Serverless Community Builder | pratikpandey.substack.com
In my last?article, we looked at one of the techniques of identifying concurrent updates/conflicts by leveraging Server(Replica) as an Actor & the advantages and disadvantages of doing so. If we went with the approach to include siblings in our Version Vectors to resolve conflicts, we still don’t have a way to track causality in the merged state. If we don’t include siblings in our Version Vectors, we can have data loss/updates. In this article, we’ll look at another approach for identifying concurrent updates/conflicts.
Dotted Version Vectors
Dotted Version Vectors solve the problems we saw with using ServerId. Let’s go over the problem with using ServerId -
Let’s try to understand what’s happening in the above diagram -
Problem with Step 7 -
If you notice, the update to Z from V, came after client 3 saw the state of V and decided to update it to Z. However, the server/replica, treats the update as concurrent, rather than sequential and stores the value of Z as a sibling. Hence we end up losing information on causality & that’s because the server does not have context at K : {(A, 2)} : [W, V], the version vector associated with the occurrence of V i.e (A,1).
Solution
We understand that the problem is because we don’t have context that can help us determine, which siblings are causally related and which are concurrent. To solve the problem, we change the structure of what’s stored inside the Version Vector, to provide more context.
Current State — [(A, 2)], [V, W]
New State — [(A, 2), [(A, 1)->V, (A,2)->W]
Now, let’s apply our new state and see how to helps -
Let’s try to understand what’s happening in the above diagram, starting from step 5, where Replica has already received the 1st message from C3 -
Advantages -
领英推荐
Disadvantages -
Conflict Resolutions
Irrespective of the type of Version Vectors we used, we saw that we still had conflicting cases, which we avoided by leveraging siblings. Siblings allow us to defer the conflict resolution and allows the system to move forward and also helps in keeping the state of the conflicting versions till the desired Conflict Resolution Strategy kicks in. We’ll talk about multiple conflict resolution strategies here -
We referred to Last-Write-Wins briefly during our?article. We generally leverage some parameter(generally timestamp) to decide our latest write and delete any siblings that occurred before the lastest write. The LWW is a great strategy for server side resolution(i.e the responsibility of doing conflict resolution doesn’t fall on the client), but suffers from inconsistent behaviours leading to data inaccuracy.
If you take into account multiple replicas, if multiple clients update the same data row concurrently, because of n/w latency or partition the last write will overwrite the value from the client & this behaviour will not be consistent.
Choose LWW for your systems preferably if you have low concurrent writes, or where you’re okay with the inconsistent behaviour.
2. Read Repair -
Read repair is a strategy where the VV conflict resolution is done at the time of reading the data. The node coordinating the read request fetches the VV of the data from all replica nodes having it, and then performs a merge on the Version Vectors.
Notice that read repair only targets doing conflict resolution for data that's actively being read. For data that's not actively touched, we can do a similar process and its called proactive repair.
There are other conflict resolution mechanism as well, but the idea was to provide all you guys with the high level details. The internals of conflict resolution will change based on the system’s choice of conflict resolution strategy.
-----------------------------
This brings us to the end of this article and the series on Version Vectors. Hopefully it helped you understand how concurrent updates in a distributed system are handled with the help of Version Vectors. We also talked about how Version Vectors evolved and the advantages and drawbacks of each evolved version. Please post comments on any doubts you might have and will be happy to discuss them! Also, if you want me to cover Conflict Resolution in detail, please comment and I’ll do the same!
-----------------------------
Thank you for reading! I’ll be posting weekly content on distributed systems & patterns, so please like, share and subscribe to this?newsletter?for notifications of new posts.
Please comment on the post with your feedback, will help me improve! :)
Until next time, Keep asking questions & Keep learning!