SetNet.Sharding
1.2.0
dotnet add package SetNet.Sharding --version 1.2.0
NuGet\Install-Package SetNet.Sharding -Version 1.2.0
<PackageReference Include="SetNet.Sharding" Version="1.2.0" />
<PackageVersion Include="SetNet.Sharding" Version="1.2.0" />
<PackageReference Include="SetNet.Sharding" />
paket add SetNet.Sharding --version 1.2.0
#r "nuget: SetNet.Sharding, 1.2.0"
#:package SetNet.Sharding@1.2.0
#addin nuget:?package=SetNet.Sharding&version=1.2.0
#tool nuget:?package=SetNet.Sharding&version=1.2.0
<p align="center"> <img src="https://raw.githubusercontent.com/Povstalez/SetNet/master/assets/icon.png" alt="SetNet" width="96"> </p>
SetNet.Sharding
Consistent-hash routing for SetNet clusters: every key has exactly one home node, and any node can tell you which.
Rooms, relay sessions and matchmaking queues in SetNet are node-local — which is fine on one server, but on many you need every client interested in room ABC123 to land on the same node. SetNet.Sharding provides that: a consistent-hash ring (virtual nodes, ~1/N key movement on membership change) mapping any string key to its owner node, plus a directory service every node answers, so a client can connect to any entry node, ask "where does key X live?", and dial the returned node. Added by composition — no base class.
Install
dotnet add package SetNet
dotnet add package SetNet.Sharding
Usage
Call ShardingRuntime.Enable() once at startup on both ends (before handler discovery).
Every server node — same node list everywhere:
ShardingRuntime.Enable();
var nodes = new List<ShardNode>
{
new ShardNode { NodeId = "eu-1", Host = "eu1.game.example", Port = 5000 },
new ShardNode { NodeId = "eu-2", Host = "eu2.game.example", Port = 5000 },
new ShardNode { NodeId = "us-1", Host = "us1.game.example", Port = 5000 },
};
var sharding = server.UseSharding(new ShardingOptions { Nodes = nodes, SelfNodeId = "eu-1" });
// server-side routing, e.g. inside a room-create handler:
if (!sharding.IsLocal(roomCode))
/* redirect the client to sharding.Locate(roomCode) */ ;
Client — ask any node, then go where the key lives:
ShardingRuntime.Enable();
var sharding = entryClient.UseSharding();
ShardNode home = await sharding.LocateAsync(roomCode);
var gameClient = new GameClient(new Configuration { Host = home.Host, Port = home.Port, /* ... */ });
await gameClient.ConnectAsync(); // rooms/relay/matchmaking for this code now work cluster-wide
Membership changes — swap the ring on every node (broadcast however you like, e.g. SetNet.Cluster):
cluster.On<NodesChanged>(msg => sharding.UpdateNodes(msg.Nodes)); // atomic swap, ~1/N keys remap
API
| Member | Purpose |
|---|---|
server.UseSharding(ShardingOptions) → ShardingServer |
directory + in-process routing |
ShardingServer.Locate(key) / IsLocal(key) / UpdateNodes(nodes) / Ring |
server-side ring access |
client.UseSharding() → ShardingClient |
directory queries |
ShardingClient.LocateAsync(key) / ListNodesAsync() |
who owns a key / full node list |
ShardRing(nodes, virtualNodes = 128) |
the ring itself — GetNode(key), GetNodes(key, n) (owner + replicas); usable standalone |
ShardingOptions |
Nodes, SelfNodeId, VirtualNodes |
ShardingRuntime.Enable() |
one-time bootstrap so the handlers are discovered |
Notes
- Rides the unified SetNet.Protocol messaging layer on the
Channels.Shardingchannel (all modules share one envelope wire type,65447) — no per-module wire ids to reserve. Serializer-agnostic: the control protocol is hand-framedbyte[], your payloads use yourSetNetSerializer. - Deterministic everywhere. The ring hashes with FNV-1a over
NodeId— the same node list yields the same ring on every node and across restarts. KeepNodeIds stable; renaming one remaps its keys. - Directory, not proxy. Clients are told where to go and connect there themselves (cheap, no extra hop). If you need transparent forwarding instead, put
SetNet.Gatewayin front and useShardRinginside its backend selector. - Consistency is yours. The package doesn't gossip membership — push
UpdateNodesto all nodes together (viaSetNet.Cluster, config rollout, orchestrator). During a brief divergence two nodes may answer differently; design flows to re-query on connect failure. - Replicas.
ShardRing.GetNodes(key, n)returns the owner plus the next n−1 distinct nodes — the natural replica set for warm standbys or redundant placement.
Documentation & source
- 🐙 https://github.com/Povstalez/SetNet — full module catalog in docs/MODULES.md
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- SetNet (>= 1.2.0)
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 |
|---|---|---|
| 1.2.0 | 135 | 8/5/2026 |