Skip to content

UUIDv7 Node Partitioning ​

UuidV7Factory defaults to RFC 9562 UUIDv7 with a 48-bit timestamp, a 12-bit monotonic counter in rand_a, and 62 effective random bits in rand_b after the RFC variant bits. This gives deterministic per-factory ordering and probabilistic cross-factory uniqueness.

Node partitioning is an opt-in distributed mitigation for fleets that can assign stable node, shard, process, or deployment IDs. It reserves the most-significant bits of rand_b for that discriminator and leaves the remaining tail bits random.

mermaid
flowchart LR
    A["TimeProvider"] --> B["48-bit unix_ms"]
    C["Lock-free factory state"] --> D["12-bit counter"]
    E["UuidV7NodePartition"] --> F["1-16 rand_b node bits"]
    G["CSPRNG"] --> H["remaining rand_b bits"]
    B --> I["UUIDv7"]
    D --> I
    F --> I
    H --> I

Layout ​

With a 10-bit partition, the high-level layout is:

FieldBitsSource
unix_ts_ms48Physical/logical time
version4UUIDv7
rand_a12Monotonic counter
variant2RFC variant
node partition10Configured node/shard ID
random tail52CSPRNG bytes

Clockworks supports 1 to 16 partition bits. A 16-bit partition allows 65,536 configured IDs and leaves 46 random bits in rand_b.

Comparison ​

ApproachStrengthTrade-off
Default UuidV7FactoryFast, simple, 62 random tail bits, strict per-instance orderingCross-factory uniqueness is probabilistic; no deterministic namespace separation
Node-partitioned UuidV7FactoryDeterministic separation between correctly assigned node IDsLess random entropy; requires correct node/shard assignment
HlcGuidFactoryEncodes node ID and HLC state for causal/distributed orderingDifferent semantics and wire contract; choose it for causal ordering, not just collision mitigation
Snowflake-style IDCompact deterministic allocation with explicit worker bits and sequenceUsually custom format rather than UUID; requires clock discipline and worker coordination
Database allocatorStrong central uniqueness and ordering policyCentral dependency, added latency, and availability coupling

Failure Modes ​

Node partitioning does not remove the need for operational discipline:

  • Two live nodes configured with the same partition can still collide probabilistically.
  • A node ID reused during overlapping deployments is not a unique partition.
  • Random entropy is reduced by the configured partition width.
  • Storage uniqueness constraints remain the final guardrail for high-assurance domains.

Use node partitioning when you need UUIDv7 compatibility plus deterministic fleet partitioning and can reliably assign non-overlapping IDs.

Released under the MIT License.