[ANN] Distributed consensus library and ecosystem with built-in DST

Hey all,

Over the past year, I have been working on an implementation of the Raft consensus algorithm in Haskell, which allows for distributed consensus. In particular, using Raft, one can create a distributed, fault-tolerant state machine. The library has been released on Hackage under the name raft-consensus. Bring your own networking and persistence layer!

Raft is tricky to get right. To ensure that the library works correctly, and respects the properties of the algorithm in practice, even under faults such as crashes and network partitions, I leveraged a technique called deterministic simulation testing (DST), using io-sim as the foundation. io-sim is pure awesomeness that should be used more.

While building out examples, I noticed other ecosystem holes that resulted in more packages. Testing the linearizability of client requests required building a simple linearizability checker: linearizable. Another piece of technology that came from this project is a generic and performant implementation of write-ahead logs via a new wal package.

Finally, in order to make it as easy as possible to build a replicated state machine in practice, I built two adapter packages:

I feel relatively confident in releasing this stuff now because, over the past week, I’ve been working on a demo: distributed software transactional memory. This program looks just like stm, but running over multiple computers.
Right now it’s just a demo, but it shows how freaking cool distributed state machines can be.


My goal, since I started helping with maintenance of Cloud Haskell, has been for Haskell to become a solid choice for distributed systems. We’re now one step closer to that reality.

If you’re interested in this stuff, I would love to get your input on this and collaborate. Development for all of this is happening here: GitHub - LaurentRDC/distributed-consensus: Haskell implementation of distributed consensus protocols with built-in support for deterministic simulation testing · GitHub

19 Likes

This is interesting to me but I’m not sure where I would jump in with the project itself.

I think I might try to plug in raft-consensus into a custom protocol and play around with it there.

Documentation on Hackage is up.

@stevechy what protocol would this be integrated with? In my experience Raft is used for stores of data (e.g. distributed key value stores à la etcd)

@LaurentRDC I was thinking of making a very simple key value store as an experiment. I was originally thinking of trying to use grapsey Grpc with Oxia as a key value store but it would be pretty cool to see how a native Haskell implementation would work. I was thinking of inventing a simple protocol to experiment with it.

This is a very impressive collection of libraries! Sorry my first response was a bit terse since I was thinking of how to dive in deeper into it.

Thanks for mentioning grapesy, I have been meaning to take a look as well, and implement either an example or even an adapter.

If by Oxia you mean this one, then that’s very much what I’ve been meaning to do as well. The reason I got interested in Raft is because there’s no good story for the management of Cloud Haskell clusters, e.g. to perform rolling upgrades. Doing so requires a metadata store (e.g. etcd for Kubernetes), so we are very much aligned.

Yes that is the Oxia I am referring to. The main reason I wanted to use it over zookeeper is that it has namespaces. With namespaces I can set up one instance that could be used for multiple projects. It has a grpc based protocol so I think that it shouldn’t be too bad to implement an Oxia client with grapesy.

I would be interested in picking up some small tasks in Cloud Haskell or these raft projects if you have any that you can point to.

1 Like

I’ve started a few issues here that are related to the Raft implementation itself (e.g. performance optimizations).

For Cloud Haskell the big one for me is this one: creating a cluster management tool for Cloud Haskell clusters. Distributed consensus is a pre-requisite, but even with this, this is a huge task.
I would say an interesting sub-challenge would be to define an interface for node discovery, with implementations via DNS and perhaps a gossip protocol as well.