Skip to content

Latest commit

 

History

History
126 lines (86 loc) · 7.71 KB

README.t.md

File metadata and controls

126 lines (86 loc) · 7.71 KB

SlimCluster

SlimCluster has the Raft distributed consensus algorithm implemented in .NET. Additionally, it implements the SWIM cluster membership list (where nodes join and leave/die).

  • Membership list is required to maintain what micro-service instances (nodes) constitute a cluster.
  • Raft consensus helps propagate state across the micro-service instances and ensures there is a designated leader instance performing the coordination of work.

The library goal is to provide a common groundwork for coordination and consensus of your distributed micro-service instances. With that, the developer can focus on the business problem at hand. The library promises to have a friendly API and pluggable architecture.

The strategic aim for SlimCluster is to implement other algorithms to make distributed .NET micro-services easier and not require one to pull in a load of other 3rd party libraries or products.

Gitter GitHub license Build

Roadmap

This a relatively new project!

The path to a stable production release:

  • ✅ Step 1: Implement the SWIM membership over UDP + sample.
  • ✅ Step 2: Documentation on Raft consensus.
  • ✅ Step 3: Implement the Raft over TCP/UDP + sample.
  • ⬜ Step 4: Documentation on SWIM membership.
  • ⬜ Step 5: Other extensions and plugins.

Docs

Packages

Name Description NuGet
SlimCluster The core cluster interfaces NuGet
Core abstractions
SlimCluster.Membership The membership core interfaces NuGet
SlimCluster.Serialization The core message serialization interfaces NuGet
SlimCluster.Transport The core transport interfaces NuGet
SlimCluster.Persistence The core node state persistence interfaces NuGet
Plugins
SlimCluster.Consensus.Raft Raft consensus algorithm implementation NuGet
SlimCluster.Membership.Swim SWIM membership algorithm implementation NuGet
SlimCluster.Serialization.Json JSON message serialization plugin NuGet
SlimCluster.Transport.Ip IP protocol transport plugin NuGet
SlimCluster.Persistence.LocalFile Persists node state into a local JSON file NuGet
SlimCluster.AspNetCore ASP.NET request routing to Leader node NuGet

Samples

Check out the Samples folder on how to get started.

Example usage

Setup membership discovery using the SWIM algorithm and consensus using Raft algorithm:

@:cs

Then somewhere in the micro-service, the ICluster can be used:

// Injected, this will be a singleton representing the cluster the service instances form.
ICluster cluster;

// Gives the current leader
INode? leader = cluster.LeaderNode;

// Gives the node representing current node
INode self = cluster.SelfNode;

// Provides a snapshot collection of the current nodes discovered and alive/healthy forming the cluster
IEnumerable<INode> nodes = cluster.Nodes;

// Provides a snapshot collection of the current nodes discovered and alive/healthy forming the cluster excluding self
IEnumerable<INode> otherNodes = cluster.OtherNodes;

The IClusterMembership can be used to understand membership changes:

@:cs

Architecture

  • The service references SlimCluser NuGet packages and configures MSDI.
  • Nodes (service instances) are communicating over UDP/IP and exchange protocol messages (SWIM and Raft).
  • Cluster membership (nodes that form the cluster) is managed (SWIM).
  • Cluster leader is elected at the beginning and in the event of failure (Raft).
  • Logs (commands that chage state machine state) are replicated from leader to followers (Raft).
  • State Machine in each Node gets logs (commands) applied which have been replicated to majority of nodes (Raft).
  • Clients interact with the Cluster (state mutating operations are executed to Leader or Followers for reads) - depends on the use case.

SlimCluster architecture

License

Apache License 2.0

Build

cd src
dotnet build
dotnet pack --output ../dist

NuGet packaged end up in dist folder

Testing

To run tests you need to update the respective appsettings.json to match your cloud infrastructure or local infrastructure.

Run all tests:

dotnet test

Run all tests except integration tests which require local/cloud infrastructure:

dotnet test --filter Category!=Integration