What does versioning mean?
Means treating each data modification as a new immutable version of data
Assume that there are two nodes and that hold the same data: name: "John".

Next, changes the name to “JohnSanFrancisco” and changes the name to “JohnNewYork” at the same time.

Vector clocks are commonly used to resolve such conflicts
What are vector clocks
- Vector clock is a
[server, version]pair associated with a data item. - It can be used to check if one version precedes, succeeds or conflicts with other data.
- It can be represented in the form of , where is the data item (key-value pair), is the version counter and is the server number
- When a data item, , is written to server , one of the following things happen:
- Increment if exists
- Else, create a new entry - '' being the first time version number
Demonstrating conflict resolution using vector clocks
Assume the following data modifications

Here, when the client reads and , it will discover a conflict (caused by being modified by and ). The conflict is resolved by client and updated data is sent to the server. Assuming that the write is handled by , we end up with
Detecting conflicts
- We can tell that a version X is an ancestor (no conflict) of version Y if the version counters of each participant in the vectors clock of Y is greater than or equal to the ones in version X.
- Example: is an ancestor of
- Version X is a sibling (conflict exists) of version Y if there is any participant in Y’s version clock who has a counter that is less than its corresponding counter in X
- Example: and have a conflict
Drawbacks of vector clocks
- Adds complexity to the client because it needs to implement conflict resolution logic
- The pairs in the vector clock could grow rapidly.
- To fix this, we can set a threshold for the number of pairs we want to hold. The oldest pairs are removed as the limit is exceeded.
- This may lead to inefficiencies in reconciliation because the descendant relationship cannot be determined accurately. However, based on this research paper published by Amazon on DynamoDB, Amazon has not yet encountered this problem in production.
Related Notes
- Meaning of consistency in distributed systems
- CAP Theorem
- Replicating data on the hash ring
- Meaning of availability in distributed systems