Playing with Lasp and CRDTs
marianoguerra.org
marianoguerra.org
I like all the steps shown and the extra comments with output values and explanation of what's going on.
One question -- saw that all update operations take self() as an argument. In the code saw it was the "Actor". Is that always a pid of the calling processes or can it be anything like an integer or a reference. If this whole thing was running in a server would that be the ID of the client or still be generated locally on the server from the process running the request.
That's a lot of boilerplate to get and set a variable.
from the github repo: "Prototype implementation of Lasp in Erlang"
Actually... thinking about it, I would hope that it'd be fairly language neutral if you really wanted it to grow.
Your device, running some Go code that talks to SQLite as well as a server running in Java could still use the same data structures and communication protcols... right?
The goal of Lasp is to allow you to write a program once and know that it will behave the same whether it is executed on one computer or distributed across many."
The idea with CRDT is to define some data structures and operations on them so that it's possible to update the data structure in a concurrent environment with potentially conflicting updates which then end up being merged automatically.
For example, take a set and the operation of updating it. Say I am in Australia and you are in US and we are trying to operate on a shared set S. We both have local versions of it on our servers and our servers replicate with each other.
Maybe I add an item x to it and you pretty much at the same time add an item y. For a short while my version of the set will be S={x}, yours will be S={y}. Then after say 250 msec I'll see your changes and you'll see my changes we'd both have S={x,y}.
Notice how time didn't really figure out in the operation, and the order didn't matter -- you could have updated your version first or I could have updated mine first, but we'd both end up with the same result. And even better, we didn't have to manually resolve a conflict. Also you could have been on Neptune and I could have been on Mercury, it would have still worked but taken longer to replicate, maybe 6 hours or something like that.
PS: Mathematically this is related to https://en.wikipedia.org/wiki/Semilattice