State-based CRDTs (CvRDTs)
State-based CRDTs (CvRDTs), also named Convergent Replicated Data Types, achieve consistency through the dissemination of full copies of their state, which should be merged to resolve conflicts.
Common examples of State-based CRDTs are sets and counters. In Python, a CvRDT could look something like the following: a dictionary with a set and a counter.
1{
2 "set": {"1", "2", "3"},
3 "counter": 5
4}
Each of the elements in the set and the counter are independently updated and then periodically merged together. Merging elements in CvRDTs are based on the mathematical principle of a join-semilattice, or simply put, finding the "maximum" between two elements.
You can think of CvRDTs like your travel itinerary. Suppose you are simultaneously planning a trip to multiple destinations (say, Paris, London, and New York) on different devices (desktop, mobile, tablet). Behind the scenes, each device would be considered a replica, and the travel plans to each city are like the different states broadcasted across these replicas. Whenever you update your travel plans on any device, it syncs up with all other devices to reflect the latest state (or itinerary in this case), ensuring you have the most up-to-date information whichever device you access.
The scripts included will demonstrate how CvRDTs maintains the latest state of data.
xxxxxxxxxx
if __name__ == "__main__":
# Python logic here
cvrdts = {
"set": {"1", "2", "3"},
"counter": 5
}
print(f"The current state of CvRDTs is {cvrdts}")