Quantum.Snowflake
1.0.0
dotnet add package Quantum.Snowflake --version 1.0.0
NuGet\Install-Package Quantum.Snowflake -Version 1.0.0
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="Quantum.Snowflake" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Quantum.Snowflake" Version="1.0.0" />
<PackageReference Include="Quantum.Snowflake" />
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 Quantum.Snowflake --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Quantum.Snowflake, 1.0.0"
#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.
#:package Quantum.Snowflake@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Quantum.Snowflake&version=1.0.0
#tool nuget:?package=Quantum.Snowflake&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Quantum.Snowflake
Quantum.Snowflake is a lightweight and customizable Snowflake ID generator for .NET, producing unique, time-based, sortable identifiers suitable for distributed systems.
Inspired by Twitter's original Snowflake algorithm, it splits the ID into:
- Timestamp
- Instance ID
- Sequence number
โ Features
- 64-bit Snowflake-style IDs (timestamp + machine + sequence)
- Plug-and-play instance ID and timestamp providers
- Built-in sequence throttling with wrap-around control
- Binary format padding for consistent bit-width representation
- Easily extendable/customizable via interfaces
- Zero external dependencies
๐ฆ Structure
Each Snowflake ID is a binary string composed of:
Component | Bits | Purpose |
---|---|---|
Timestamp | 41 | Milliseconds since a custom epoch |
InstanceId | 10 | Identifies the machine or worker |
Sequence | 12 | Sequence number within the same tick |
๐ก Example
// Generate a new ID
var snowflake = SnowflakeIdGenerator.New();
// Get full binary string
Console.WriteLine(snowflake.Get()); // 64-bit binary string
// Convert to long
Console.WriteLine(snowflake.ToLong()); // Unique, sortable long
โโ```
## ๐งฉ Integration
You can plug in your own timestamp source or machine ID strategy:
```csharp
var customTimestamp = new TimeStampIdGenerator(
startingPoint: new DateTime(2020, 1, 1),
dateTimeProvider: new MyCustomDateTimeProvider()
);
var machineId = new MyMachineIdGenerator(); // Must implement IMachineIdGenerator
var sequencer = new Sequencer(12); // Custom bit-width
SnowflakeIdGenerator.Set(customTimestamp, machineId, sequencer);
๐ Use Cases
Quantum.Snowflake is ideal for:
- Distributed systems needing globally unique identifiers
- Order-preserving IDs for events, messages, or logs
- Sharded databases with local instance ID logic
- ID generation without relying on database identity columns
- High-throughput message queues and event sourcing
- Distributed caching or temporary object identifiers
๐ง Design Notes
- IMachineIdGenerator allows plug-in strategies for per-instance IDs.
- Sequencer wraps around at 4095, matching classic Snowflake behavior.
- TimeStampIdGenerator allows custom epochs and datetime providers.
- All components use bitwise padding to maintain consistent ID lengths.
๐งช Installation
dotnet add package Quantum.Snowflake
๐ Related Packages
- Quantum.Tempo: Calendar-agnostic date/time engine
- Quantum.Sequence: Generic cyclic sequencer used in this package
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Quantum.Core (>= 0.0.101)
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.0.0 | 204 | 8/5/2025 |