Mark As Completed Discussion

Types of CRDTs

Moving on from imagining CRDTs as the ultimate scriptwriters for an epic franchise, let's dive deeper into the genre and explore the types.

Op-based or Commutative Replicated Data Types (CvRDTs) are like a good mystery franchise, you can follow the scenes in any order and the twist will hit you nonetheless. In CvRDTs, operations commute and can be processed in any order.

A common version of CvRDT is the Observed-Remove Set (OR-Set), like a versatile actor that brings in more to the role. In OR-Set, you can add or remove elements and they handle remove operations in a more intelligent way, allowing smooth reconciliation of parallel operations.

State-based or Convergent Replicated Data Types (CmRDTs) are like a character-driven franchise; the characters (states) get updated and interact independently, but a right script (merge function) combines their storylines flawlessly on the big screen (converges to the same state).

An example of CmRDT is the Positive-Negative Counter (PN-Counter), comparable to that character who has both virtues and vices, counts separately, but in the end, we see the growth (net count). These counters handle increments and decrements separately and are useful for situations where individual upvotes and downvotes, like in a finance app or movie ratings, need to be tracked.

The accompanying Python code is an example of a PN-Counter. 'p' represents the positive count of increments and 'n' the negative count of decrements. When asked for the value, it returns the net count (p - n). This CRDT, like a lead actor, wins our hearts by showing the true colors (net effect) of the journey (increments and decrements) so far.

Remember, CRDT types are like genres, each bringing a new charm but true magic happens when they blend together seamlessly. As a seasoned movie buff or a finance guru would know, it's the right mix of elements that make the experience count.

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