Dot.Raft 0.0.3-beta.5

This is a prerelease version of Dot.Raft.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Dot.Raft --version 0.0.3-beta.5
                    
NuGet\Install-Package Dot.Raft -Version 0.0.3-beta.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Dot.Raft" Version="0.0.3-beta.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dot.Raft" Version="0.0.3-beta.5" />
                    
Directory.Packages.props
<PackageReference Include="Dot.Raft" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Dot.Raft --version 0.0.3-beta.5
                    
#r "nuget: Dot.Raft, 0.0.3-beta.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Dot.Raft&version=0.0.3-beta.5&prerelease
                    
Install Dot.Raft as a Cake Addin
#tool nuget:?package=Dot.Raft&version=0.0.3-beta.5&prerelease
                    
Install Dot.Raft as a Cake Tool

Dot.Raft

Dot.Raft is a modular implementation of the Raft consensus algorithm in .NET, built with testability, clarity, and extensibility in mind.

It aims to provide a maintainable and verifiable foundation for distributed systems that require consensus, while remaining easy to reason about and simulate.


Goals

  • Faithfully implement the Raft algorithm as described in the original paper
  • Keep the codebase test-driven and minimal
  • Provide a reusable IRaftNode interface for external usage
  • Allow realistic simulation of clusters using a custom test harness
  • Enable verification of cluster behavior under partitions and message delays
  • Maintain clean separation between Raft logic and messaging/state management

Structure

The repository is organized into the following projects:

  • Dot.Raft — the core Raft implementation
  • Dot.Raft.TestHarness — tools for simulating and testing clusters
  • Dot.Raft.Tests — unit tests for internal components
  • Dot.Raft.TestHarness.Tests — high-level integration tests using the test harness
  • Dot.Raft.Testing.Utilities — common testing utilities shared across test projects

Features Implemented

  • Leader election and heartbeats
  • Log replication
  • Safety guarantees for log consistency
  • State machine command application
  • Message transport abstraction (IRaftTransport)
  • Logical time simulation

Getting Started

To create a Raft node:

var node = new RaftNode(
    nodeId: new NodeId(1),
    peers: new List<NodeId> { new(2), new(3) },
    transport: new YourTransport(),
    electionTimer: new YourElectionTimer(),
    heartbeatTimer: new YourHeartbeatTimer(),
    stateMachine: new YourStateMachine()
);

await node.StartAsync();

The node exposes methods such as:

ReceivePeerMessageAsync(...) — for handling incoming messages

SubmitCommandAsync(object command) — to submit a command to the replicated state machine

Accept(IRaftNodeVisitor) — for exposing internal state for testing or diagnostics


Testing and Simulation

The test harness allows for simulating clusters, partitions, and logical time:

var cluster = ClusterFactory.Create(3);

await cluster.TickUntilLeaderElected();
await cluster.SubmitToLeaderAsync("set x = 42");
await cluster.TickAllAsync(50);

A fluent scenario API is also available:

await ScenarioBuilder.Build(3)
    .Then(x => x.TickUntilLeaderElected())
    .Then(x => x.SubmitCommand("cmd"))
    .Then(x => x.Tick(50))
    .Then(x => x.AssertAllApplied());

Cluster state can be inspected using the visitor pattern:

cluster.VisitNodes(new DebugVisitor(output));

Or you can write your own visitor:

public class StatePrinter : IRaftNodeVisitor
{
    public void Visit<TStateMachine>(
        NodeId id, Term term, RaftRole role, State state, TStateMachine stateMachine)
        where TStateMachine : IStateMachine
    {
        Console.WriteLine($"Node {id.Id} | Role: {role} | Term: {term.Value}");
        Console.WriteLine($"  Log: {string.Join(", ", state.GetLogEntries())}");
        Console.WriteLine($"  CommitIndex: {state.CommitIndex}, LastApplied: {state.LastApplied}");
    }
}

Project Structure

src/
├── Dot.Raft                  # Core Raft logic and abstractions
├── Dot.Raft.TestHarness      # Cluster simulation with in-memory transport

tests/
├── Dot.Raft.Tests                  # Unit tests for RaftNode
├── Dot.Raft.TestHarness.Tests      # Cluster behavior tests
├── Dot.Raft.Testing.Utilities      # Shared test helpers (timers, transports, etc.)
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.3-beta.6 38 4/5/2025
0.0.3-beta.5 119 3/31/2025
0.0.3-beta.4 102 3/30/2025
0.0.3-beta.3 101 3/30/2025
0.0.3-beta.2 103 3/30/2025
0.0.3-beta.1 103 3/30/2025
0.0.2 123 3/30/2025
0.0.2-beta.8 109 3/30/2025
0.0.1 128 3/30/2025