Need & Utility of CRDTs
As we established in the previous screen, CRDTs are the superheroes of distributed systems, always coming to the rescue in multi-user real-time collaboration applications. A good example in the context of finance might be something like a distributed ledger system used in cryptocurrency transactions to maintain consistency, but CRDTs can also come to the rescue in much simpler everyday applications.
Imagine planning a travel trip with your friend. You both have different destinations in mind but want to come up with a combined itinerary. Like a seasoned director weaving your favorite franchise together, a set CRDT could merge your distinct itineraries together ensuring a coherent plotline - your combined travel destinations.
Each of you could independently and concurrently add different or similar destinations to your individual sets. Even if changes were made at the same time, the end result will still be a set that includes all unique destinations from both your suggestions. No matter what order the changes are incorporated, the end result is consistent.
The implemented code displays the scenario where two sets of destinations are merged. The CRDT's key characteristic shines through: regardless of the order in which the destinations are added, the result is the same unified set.
In the end, it's like filming different sequels (your individual travel destinations) that amalgamate into an epic franchise (the final list of unique destinations) consistent across all theaters (replicas in the network).
xxxxxxxxxx
if __name__ == "__main__":
# Imagine the scenario of a distributed travel booking system
# Initialize the set of destinations
destinations = set()
# Diverse set of destinations a travel enthusiast wants to visit
destination_1 = {'Australia', 'France', 'Japan'}
destination_2 = {'Spain', 'Australia', 'USA'}
# Both entities update their destinations
destinations = destinations.union(destination_1, destination_2)
print(f'Destinations: {destinations}')