Mark As Completed Discussion

CRDTs or Conflict-free Replicated Data Types are a broad classification under which we have a rich and diverse set of data structures. Each of these structures fulfills specific requirements towards concurrent operations, conflict resolution, and locality of operations.

Just as you choose a data structure in conventional computer programming problems, considering factors like search time, storage requirements, and the nature of operations; in a distributed system scenario, the choice of CRDT also plays a pivotal role. It's very similar to selecting a film for a movie marathon, considering the genre, theme, and audience preference.

Let's explore some of the critical types of CRDTs:

  • State-based or Convergent CRDTs (CvRDTs): In this type, every replica maintains a state that gets merged with states from other replicas. This merge operation is both commutative and idempotent, resulting in an eventual consistency. A primary example of this type is a Grow-only Set (G-Set), where elements can be added, but not removed.

  • Operation-based or Commutative CRDTs (CmRDTs): In CmRDTs, when a local operation is performed, it is broadcasted to all other replicas. Since operations in CmRDTs are commutative, replicas can apply these operations in any order. Consider the example of an Increment-Decrement Counter (ID-counter), where counts are incremented and decremented locally and kept consistent across replicas.

Remember, these are not the only CRDTs, and there are more complex variants like LWW-Element-Set (Last-Write-Wins-Element-Set) or 2P-Set (Two-Phase Set). You choose them per the demands of your distributed architecture - similar to the customization and diversity we find in travel destinations. Rome for arts, Switzerland for landscapes, and New York for finance.

Next, we'll go over to executing a 2-element set in Python to show you how the different operations are performed in CRDTs.

PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment