Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

SolinkCorp/flake-id-generators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to Flake ID Generators Home Page Build status

Original source: http://flakeidgenerators.codeplex.com/

Flake ID Generators is a set of decentralized, k-ordered id generation services in C#.

  • FlakeGen.Id64Generator - generates 64-bit ids. The implementation is heavily derivative of Twitter's Snowflake written is Scala.
  • FlakeGen.IdGuidGenerator - generated Guid (128-bit) ids
  • FlakeGen.IdStringGeneratorWrapper - a wrapper for FlakeGen.Id64Generator returning k-ordered ids in various string formats (e.g. number, hex, base 32)

Both services generates k-ordered ids (read time-ordered lexically). Run one on each node in your infrastructure and they will generate conflict-free ids on-demand without coordination.

Features

FlakeGen.Id64Generator

  • Generator written in C#
  • Compact ids (under 64 bit) directly sortable
  • Id is composed of:
    • time - 41 bits (millisecond precision)
    • configured instance id - 10 bits - gives us up to 1024 instances
    • sequence number - 12 bits - usually 0, incremented when more than one id is requested in the same millisecond and reset to 0 when the clock ticks forward. Rolls over every 4096 per machine.
      • The generator has protection mechanism for sequence roll over in the same millisecond.

FlakeGen.IdGuidGenerator

  • Generator written in C#
  • Generated ids directly sortable
  • Id is composed of:
    • time - 64-bits - milliseconds since the epoch (Jan 1 1970)
    • configured instance id - 48 bits - it can be MAC address from a configurable device or database sequence number or any other 6 bytes identifier
    • sequence number - 16-bits - usually 0, incremented when more than one id is requested in the same millisecond and reset to 0 when the clock ticks forward. Rolls over every 65536 per machine.