Mark As Completed Discussion

Remember how the finance team at Netflix would work with movies and codes? Let's use that analogy to understand the different types of CRDTs.

CRDTs are classified into two broad categories: Operation-based (op-based) CRDTs and State-based (state-based) CRDTs.

  • Op-based CRDTs: These types of CRDTs propagate operations rather than states. Examples of Op-based CRDTs are G-Counter (Grow-only Counter) and PN-Counter (Positive-Negative Counter). Imagine your favorite travel destination: each site you visit (operation) increases your overall experience (state); the order of the sites isn't significant.

  • State-based CRDTs: These propagate their state, not the operations. Here, the order of merging does matter. Examples of state-based CRDTs are G-Set (Grow-only Set) and 2P-Set (Two-Phase Set).

Let's use an analogy from the world of streaming services. You can think of G-Sets as the Netflix watchlist, where you just keep adding favorite shows like 'Brooklyn 99' or 'The Office', but can't remove any. In contrast, consider 2P-Sets as the travel bucket list, where you can mark off destinations ('Avengers: Endgame') after visiting. Note that once a site is marked off, it's considered 'tainted' and can't be visited again.

In the provided Python script, we represent these with standard Python set. We're adding elements to G-set (g_set), and you'll notice that we can't remove any. Next, we create a P-set (p_set and tombstone_set), where we can 'remove' an item by moving it to the 'tombstone' set.

But so far, we're only dealing with two types out of a range of CRDTs available. More complex systems might require LWW-Registers (last-write-wins), MV-Registers (multi-value), and so on. Remember, just as there are diverse movie genres to cater to all sorts of viewers, in the world of CRDTs, there is a data type for every kind of application!

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