Skip to content

OrderedIdGenerator Class ​

Definition ​

Generates compact, time-ordered 64-bit identifiers using a fixed bit layout: 41-bit timestamp (milliseconds since a custom epoch), 10-bit node id, and 12-bit sequence.

  • Namespace: JASE
  • Assembly: JASE.IdGenerator.dll

Constructors ​

NameDescription
OrderedIdGenerator(int nodeId, DateTime epochUtc, OrderedIdClockMode mode = null, int maxLogicalSkewMS = null)Initializes a new generator with explicit node id, custom epoch, and clock mode.
OrderedIdGenerator(int nodeId, OrderedIdClockMode mode = null, int maxLogicalSkewMS = null)Initializes a new generator using DefaultEpoch.

Fields ​

NameDescription
NodeBitsNumber of bits used for the node id field.
NodeMaskBitmask for extracting the 10-bit node id field.
NodeShiftBit shift for the node id field (sequence is the least-significant field).
SequenceBitsNumber of bits used for the per-millisecond sequence field
SequenceMaskBitmask for extracting the 12-bit sequence field.
TimestampBitsNumber of bits used for the timestamp field.
TimestampMaxMaximum representable timestamp value (41 bits).
TimestampShiftBit shift for the timestamp field (timestamp is the most-significant field).

Properties ​

NameDescription
DefaultEpochJASE snowflake epoch (2025-07-11 UTC). Encoded timestamps are milliseconds since this instant.
EpochThe epoch for this generator instance.
NodeIdNode identifier encoded into generated IDs (0..1023).
TwitterEpochTwitter Snowflake / IdGen default epoch (2010-11-04 01:42:54.657 UTC).

Methods ​

NameDescription
OrderedIdValue Decode(long id)Decodes an identifier into its component fields (timestamp, node id, sequence).
OrderedIdGenerator FromEnvironment(DateTime epochUtc, OrderedIdClockMode mode = null, int maxLogicalSkewMS = null)Creates a generator using a custom epoch and the node id from JASE_ID_GENERATOR_NODE (0..1023).
OrderedIdGenerator FromEnvironment(OrderedIdClockMode mode = null, int maxLogicalSkewMS = null)Creates a generator using DefaultEpoch and the node id from JASE_ID_GENERATOR_NODE (0..1023).
bool IsOrderedId(long value)Determines whether a value conforms to the OrderedId bit layout and decodes to a plausible timestamp for this generator instance.
long NextId()Generates the next ordered identifier.

Remarks ​

This generator produces IDs that are monotonically increasing per generator instance (per node), with ordering primarily determined by the timestamp component.

The timestamp is stored as a 41-bit millisecond offset from Epoch. The remaining bits encode the node id and an intra-millisecond sequence counter.

Clock behavior is controlled by OrderedIdClockMode:

WallClock is Snowflake-compatible: the ID timestamp tracks real UTC time. If the clock moves backwards or the sequence overflows within a millisecond, generation will wait. LogicalClock is a bounded logical clock optimized for throughput: it avoids blocking on minor clock rollback and may advance the logical timestamp slightly ahead of real time up to a configured bound.

Time source note: this implementation uses a monotonic stopwatch-based clock with periodic resynchronization to real UTC to mitigate system clock adjustments (NTP steps, VM time jumps, manual changes).