Skip to the content.

Conflict-free Replicated Date Types


tags:- CRDT —

What is CRDT

In many system, some date needs to be replicated and stored distributively. Examples are:

All above need to handle the concurrent distributed data modifications and achieve data consistency.

There are two possible ways:

Conflict-free Replicated Data Types (CRDTs) are used in systems with optimistic replication, where they take care of conflict resolution.

Moreover, an important characteristic of CRDTs is that they support decentralised operation: they do not assume the use of a single server, so they can be used in peer-to-peer networks and other decentralised settings. In this regard CRDTs differ from the algorithms used by Google Docs, Trello, and Figma, which require all communication between users to flow via a server.

Examples

We could try broadcasting the non-collaborative version of these operations: Delete ingredient 0; Prepend “Olive “ to ingredient 1. But if another user applies those operations literally in that order, they’ll end up with “Olive Salt”

And the correct result should be:


(Semantics)

We’d like to preserve both users’ edits. Also, since it’s a recipe, the ratio of amounts is more important than their absolute values. Thus you should aim for the following result:

Algorithm

OP-Based CRDTs (Commutative replicated data type)

It is commutative replicated data type, because the order how messages get received does not matter. -1+2 = 2-1.

It is assumed that when a user broadcasts a message, it is eventually received by all collaborators, without duplication (i.e., exactly-once). For example, each user could send their messages to a server; the server stores these messages and forwards them to other users, who filter out duplicates.

Algorithms in this style are called op-based CRDTs. They work even if the network has unbounded delays or delivers messages in different orders to different users.

Synchronization Workflow

Key Principles:

Workflow:

Advantages of Operation-Based Synchronization:

See here to understand when gossip protocol stops

State-Based CRDTs (convergent replicated data types)

A replica receives updates(operations) from user, apply them locally and sends its full local state to other replicas. Replicas receives the full state from another replica and call merger function to merge with its local state.

Synchronization Workflow

Convergence Detection

TBA

References