Appearance
JASE.UuidFactory
JASE provides a high-performance, allocation-free UUID factory designed for modern distributed systems and database workloads.
It supports:
- UUIDv4 (random)
- UUIDv7 (time-ordered, RFC 9562 compliant)
- SQL Server–optimized COMB GUIDs
- PostgreSQL-friendly UUIDv7
All generation paths are thread-safe and require no heap allocations.
Why not just use Guid.CreateVersion7()?
Guid.CreateVersion7() is a solid default for general UUIDv7 usage. JASE adds capabilities it doesn’t target:
- Monotonic sequencing when generating many IDs per millisecond
- Optional node partitioning for multi-process/multi-host workloads
- SQL Server–optimized COMB GUIDs for clustered index locality
- BIGINT derivation for UUIDv7 and COMB values
UUIDv7 (RFC 9562)
UUIDv7 embeds a 48-bit millisecond Unix timestamp in the high-order bytes, producing values that:
- Sort chronologically
- Improve database index locality
- Remain globally unique
- Remain RFC-compliant
Monotonic Within a Millisecond
When multiple UUIDs are generated within the same millisecond:
- A per-millisecond counter is incremented atomically
- If the clock moves backwards, the previous timestamp is retained
- If the counter wraps, the timestamp is advanced safely
This guarantees stable ordering under concurrency. The counter lives on UuidFactory (one per process). That is cheap for a single writer and will contend if every core mints through the facade. For all-core throughput, construct a UuidGenerator per thread so each has its own CAS line.
Throughput Characteristics
- 12-bit counter (non-node mode) → 4,096 UUIDs per millisecond
- 8-bit counter (node mode) → 256 UUIDs per millisecond per node
Those ceilings are per generator, not per machine. One UuidFactory shared across all cores still hits the 4,096/ms (or 256/ms with node mode) budget, and the CAS itself becomes the limiter long before the counter wraps.
All operations are implemented using atomic CAS loops and do not allocate memory.
SQL Server COMB GUIDs
SQL Server stores uniqueidentifier values in a byte-swapped format for comparison.
JASE provides a COMB-style GUID optimized for SQL Server clustered indexes:
- 48-bit timestamp stored in the high-order sort bytes
- 14-bit per-millisecond payload (counter or node+counter)
- Remaining bytes filled with random entropy
Why 14 bits?
Two high bits of byte 8 are reserved for the RFC 4122 variant.
That leaves 14 usable bits for the ordered payload.
- Non-node mode → 16,384 IDs per millisecond
- Node mode → 4-bit node + 10-bit counter (1,024 IDs per millisecond per node)
The implementation aligns internal state width with actual GUID bit layout to avoid silent counter truncation.
Multi-Node Support
JASE supports optional node partitioning:
- 4-bit node identifier (0–15)
- Configurable via
JASE_NODE_IDenvironment variable - Safe under concurrency using volatile reads
Node mode allows horizontal scaling across multiple services or machines without coordination.
BIGINT Primary Key Derivation
For UUIDv7 and SQL COMB values, JASE can derive a monotonic BIGINT key:
csharp
long key = UuidFactory.GetPrimaryKey(guid);The derived key is timestamp + ordered counter/node payload only — the UUID's random tail is discarded. That keeps the value compact and k-sortable, but uniqueness is not automatic across writers. See Identifier layouts for the frozen 1.x bit contract.
| Deployment | Requirement |
|---|---|
| Single process | Safe as-is |
| Multiple processes / hosts | Enable UuidConfig.SetUseNode(true) and give each writer a distinct node id (0..15) |
| Larger node space / no UUID parent | Prefer OrderedIdGenerator (10-bit node, 12-bit sequence) |
Full GUID primary keys remain unique without node mode because they retain the random bits.
UuidFactory / UuidConfig are process-wide. Construct a UuidGenerator when two libraries in one host must not share node/CSPRNG settings, or when many threads mint as fast as possible.
Benchmarks
Published comparison is single-thread mint only (table below). Multi-thread / Parallel.For jobs exist under Benchmarks/UuidGenerators but are not cited here — process-wide monotonic counters change that race.
Single-thread minting is allocation-free and ahead of UUIDNext, Medo (which allocates 40 B/op), and Guid.CreateVersion7() on this machine/job. That is a microbenchmark win (ns), not a product SLA. All-core Parallel.For through UuidFactory is the wrong comparison: libraries that do not keep a process-wide monotonic counter will win that race. Use a UuidGenerator per thread when that is the workload.
The table below is one machine, one job. Re-run Benchmarks/UuidGenerators (*UuidBenchmarks*) before quoting it.
AMD Ryzen 7 PRO 7840U, .NET 10.0.11, BenchmarkDotNet 0.15.8, job JaseId (1,048,576 invocations, 20 iterations), 2026-08-17.
| Method | Mean | Allocated |
|---|---|---|
| JASE_SqlComb | 33.8 ns | — |
| JASE_V7 | 39.8 ns | — |
| Medo_SqlServer | 42.0 ns | 40 B |
| Medo_V7 | 52.9 ns | 40 B |
| UuidNext_Postgres | 54.5 ns | — |
| UuidNext_SqlServer | 56.5 ns | — |
| Microsoft_V7 | 60.8 ns | — |
| RTComb_SqlServer | 69.2 ns | — |
| RTComb_PostgreSql | 74.5 ns | — |