Mark As Completed Discussion

Implementing a basic CRDT example

Now we've moved onto the next destination of our journey, stepping into the lab (or should we say, studio?) to create our very own CRDT (the leading star of our movie, or in our distributed systems).

Remember how we talked about set union as an operation in CRDTs? Let's bring that to the script of our film. Imagine you're planning an exciting world tour like a seasoned traveler (or should we say, director?), with two travel itineraries (let's call them Set A and Set B). Disparate as they are, we want to merge them into one great travel plan.

Consider Python sets representing our travel-plan CRDTs, made up of destinations you wish to visit worldwide (because programmers also deserve a vacation!). Let Set A contain 'Paris' (we can't miss the Eiffel Tower), and Set B contain 'New York' (Statue of Liberty is waiting!).

Our task is to write a merge() function that will merge both the sets using the built-in union() method of Python sets (well, what could be better than visiting both?).

Check out the Python code where we've done just that. Simply run the code to see your merged travel-plan. Creating a basic CRDT is as easy as that!

The takeaway? CRDTs are all about merging and reconciling, much like blending exotic locations to create a perfect travel itinerary or weaving subplots into a blockbuster film.

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