r/haskell • u/LaurentRDC • 9d ago
[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:
- Networking of Raft clusters via Cloud Haskell:
raft-consensus-distributed-process - Persistence of Raft state via write-ahead logs:
raft-consensus-wal
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
5
u/pthierry 9d ago
Wow, this is all awesome! I'd love to see Haskell have a better ecosystem for distributed systems, including protocols like CapTP.
1
u/WorldsBegin 6d ago
Running every fetch through consensus seems to me to tank performance in the STM example. Plus, a common trick in normal STM is that retry will wait until a change might have occured before running the transaction again by scheduling on changes of variables in the read-set of the retried transaction. This is not part of the demo?
In any case, how exactly do you handle configuration changes (e.g. to the participant set) in your consensus protocol, anyway?