Hacker News new | past | comments | ask | show | jobs | submit login

How do CRDTs work with denormalized data, or more generally, data where some fields have invariants that must be maintained between them? Let's say we have an object with an array of strings and a count of that array:

    {
        "words": ["a", "b", "c"],
        "count": 3
    }
Now suppose users A and B edit the document so that one word is deleted, and two words are added, respectively:

    {
        "words": ["a", "b"],
        "count": 2
    }


    {
        "words": ["a", "b", "c", "d", "e"],
        "count": 5
    }
What probably should happen now is that we reach the state where `words` is `["a", "b", "d", "e"]` and `count` is `4`, but is that really what would happen? That would require the CRDT to understand changes to `count` as increment/decrement operations, but aren't there also situations where you'd simply want one of the two values to win?



Yes, it would work if you implement the schema correctly: among the standard value types there are also counter types. See for example https://automerge.org/docs/types/counters/


I think with CRDT's you wouldn't just have an integer type. You would have to choose your int type acording to the operations you would want done for it. So it could be declared as a "register" crdt, in which case the semantics would be of set and override, or it could be declared as a counter, with semantics of increment/decrement.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: