SnowflakeID.Net 1.0.0

dotnet add package SnowflakeID.Net --version 1.0.0                
NuGet\Install-Package SnowflakeID.Net -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="SnowflakeID.Net" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SnowflakeID.Net --version 1.0.0                
#r "nuget: SnowflakeID.Net, 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.
// Install SnowflakeID.Net as a Cake Addin
#addin nuget:?package=SnowflakeID.Net&version=1.0.0

// Install SnowflakeID.Net as a Cake Tool
#tool nuget:?package=SnowflakeID.Net&version=1.0.0                

SnowflakeID.Net

A thread-safe mechanism for generating snowflake IDs.

Introduction

From the Snowflake ID Wikipedia page:

Snowflake IDs, or snowflakes, are a form of unique identifier used in distributed computing. The format was created by Twitter (now X) and is used for the IDs of tweets. It is popularly believed that every snowflake has a unique structure, so they took the name "snowflake ID".

This package provides a mechanism for generating snowflake IDs containing a timestamp, data center ID, worker ID, and sequence number. The sequence number is incremented if another caller concurrently generates a snowflake ID for the same data center ID and worker ID.

Each combination of data center ID and worker ID should be a singleton to prevent duplicate IDs from being generated.

Example Usage

The SnowflakeProvider class provides the Next method that generates a snowflake ID for the specified data center ID and worker ID. The provider class should be a singleton across all applications that use it.

To generate a new snowflake ID for data center 1 and worker ID 1:

var snowflakeId = SnowflakeProvider.Next(1, 1);

If the snowflake ID functionality cannot be centralized into a service with a singleton instance of the provider class, the Snowflake class can be used independently in multiple places as long as each combination of data center ID and worker ID are singletons across your domain context.

To use the Snowflake class for a specific data center ID and worker ID (in this case data center ID 2 and worker ID 4):

var snowflakeGenerator = new Snowflake(2, 4);
var snowflakeId = snowflakeGenerator.Next();
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.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
1.0.0 50 1/26/2025