3 ms·
> I always wondered if it would be possible to create a more general purpose "structured data" CRDT. Technically yes; one approach would be to use a list CRDT
by paulgb 3y ago
> I always wondered if it would be possible to create a more general purpose "structured data" CRDT.
Technically yes; one approach would be to use a list CRDT containing representations of operations on the data structure. Each replica would play the operations forward and reject any that broke the schema to “project” the operations onto a local representation of the shared data structure.
So in your example, the operation to set state: notStarted would be rejected if a completion date were present.
Besides the fact that the computational cost of the data structure will only ever grow, another consideration is that even though you are locally only appending to the list of operations, operations from peers may arrive that are not at the end of the global order.
This approach would only guarantee that the data is consistent and meets the schema — it doesn’t guarantee that merges are semantically what a user would expect.