raft-consensus: Haskell implementation of the Raft consensus protocol

[ bsd3, consensus, distributed-systems, library ] [ Propose Tags ] [ Report a vulnerability ]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0
Change log CHANGELOG.md
Dependencies base (>=4.18 && <4.23), binary (>=0.8 && <0.9), containers (>=0.7 && <0.9), io-classes (>=1.11 && <1.12), microlens-platform (>=0.4 && <0.5), random (>=1.3 && <1.4), transformers (>=0.6 && <0.7) [details]
License BSD-3-Clause
Copyright Laurent P. René de Cotret
Author Laurent P. René de Cotret
Maintainer laurent.decotret@outlook.com
Uploaded by LaurentRDC at 2026-11-30T21:46:46Z
Category Distributed Systems, Consensus
Home page https://github.com/LaurentRDC/distributed-consensus
Source repo head: git clone https://github.com/LaurentRDC/distributed-consensus(raft-consensus)
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 5 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for raft-consensus-0.1.1.0

[back to package description]

raft-consensus

Haskell implementation of the Raft consensus protocol, with built-in support for deterministic simulation testing.

This library lets you bring your own pure state machine, persistence layer, and communication layer to implement a fault-tolerant, strongly-consistent, distributed state machine.

Features of the Raft algorithm include:

  • Leader election;
  • Log replication;
  • Log compaction (i.e. snapshotting);
  • Membership changes;
  • Client request pipelining;
  • Read-only query optimizations;

The goal is to have feature-parity with industry standard implementations such as etcd's Raft implementation.

Development

This library can be built using cabal:

$ cabal build

and tests can be run with:

$ cabal test

Deterministic simulation testing

Cluster properties and client request linearizability are tested under two modes: with, and without, schedule exploration.

In both cases, the cluster's and clients' initial conditions are generated at random by QuickCheck: timeouts, cluster configuration, fault schedules, etc.

Without schedule exploration, a simulated trace is run from these initial conditions. This is relatively fast, and allows to explore the behavior of the system under many initial conditions. You can tweak the number of tests run in this mode using the quichcheck-tests option. For example:

cabal test --test-options='--quickcheck-tests=1000'

With schedule exploration, the system is started in randomly-generated conditions. However, whenever the simulation reaches a branching-point, timing-wise, both branches are explored separately as tests. This is much slower, but allows to detect races in the execution of a cluster. You can tweak the number of tests in this mode using the num-racy-tests option. For example:

cabal test --test-options='--num-racy-tests=5'

Replaying a failure

During the course of development, you may see a test failure for the deterministic simulation test suite:

$ cabal test
Running 1 test suites...
Test suite raft-consensus-test: RUNNING...
raft-consensus
  Raft
    Property tests
      Cluster properties: FAIL
        <snip>
        Use --quickcheck-replay="(SMGen 6009993106432336185 7272677387067049729,0)" to reproduce.
        <snip>

This is great news! You can replay the specific failing scenario using --quickcheck-replay in combination with test-options:

$ cabal test --test-options='--quickcheck-replay="(SMGen 6009993106432336185 7272677387067049729,0)"'