Platform Manual
Sync and Replication Concepts
Consistency Models
the article provides an overview of the concepts of eventual and causal consistency in ditto eventual consistency the following scenario provides a walkthrough of the mechanics of version vectors, their role in determining merging behavior, and how different peers contribute to data replication the hlc uses the uint128 data type to represent the site id and 64bit timestamp in ditto; however, for simplicity, the following scenario uses basic string and number types instead local peer a document 123abc links to a version vector that indicates its locally stored document is currently at vector version 5 the most recent incoming remote peer b changes were incorporated and merged at version 1 the remote peer c changes were incorporated and merged at vector version 4 documentid "123abc" version vector { "a" 5, "b" 1, "c" 4 } local peer a receives document changes from remote peer b the incoming document's version vector indicates the remote peer b incoming version vector is value 4 the most recent incoming remote peer b changes were of version 1 ; a value less than the incoming document version vector value of 4 since 4 is greater than 1 , the local peer a determines that the changes are new and should be incorporated and merged in order to remain consistent documentid "123abc" version vector { "a" 5, "b" 1, //merge in {"b" 4} because 4 > 1 "c" 4 } causal consistency causal consistency is guaranteed by ditto it is causally consistent across any number of related changes, across many documents and different collections, as long as they are within the same ditto appid to give an intuition about causal consistency, imagine the following scenario on a social network, bob posts a message bob "i lost my cat" then after some time, he posts bob "i found him! what a relief!" to which sue replies sue "great news!" in contrast, an eventually consistent database shows messages in any order bob "i lost my cat" sue "great news!" bob etc ditto's causal consistency ensures that if a new message is written after seeing some prior message, then the new message is not visible unless that prior message is also visible to help differentiate causal consistency from stronger consistency models, imagine that alice replies alice "wonderful!" causal consistency allows the two concurrent messages "great news!" from sue and "wonderful!" from alice to appear in any order both of the following results are valid with causal consistency bob "i lost my cat" bob "i found him! what a relief!" sue "great news!" alice "wonderful!" and bob "i lost my cat" bob "i found him! what a relief!" alice "wonderful!" sue "great news!"