Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emphasis of optional subfields for v7 #101

Closed
fboulnois opened this issue Jun 4, 2023 · 4 comments · Fixed by #103
Closed

Emphasis of optional subfields for v7 #101

fboulnois opened this issue Jun 4, 2023 · 4 comments · Fixed by #103

Comments

@fboulnois
Copy link

I have an implementation of v7 UUIDs for Postgres based on the original draft. I stumbled upon the updated draft today and I think the latest draft places too strong an emphasis on the optional subfields in v7 UUIDs (changed in #91).

In the original draft, the implementation was straightforward: 48 bits for a Unix timestamp in milliseconds and 74 bits of randomness.

The updated draft include a more detailed description of the 74 bits of randomness, but in doing so I think it places too much emphasis on the use of timestamps or counters in the optional subfields. This raises the barrier to implementation (I was initially confused and concerned I needed to reimplement or add code to remain conformant) and in my opinion we should steer implementations away from relying on anything other than a CSPRNG in the random bits unless there is a specific need for all the reasons described in #86. Additionally, I think encouraging the use of timestamps or counters in those subfields can lead to incompatible implementations of v7 UUIDs even if they are optional.

Therefore, my suggestion would be either to:

  1. Remove the numeric bullet points and rephrase the section as:

UUIDv7 values are created by allocating a Unix timestamp in milliseconds in the most significant 48 bits and filling the remaining 74 bits, jointly, excluding the required version and variant bits, with pseudo-random data in the subfields.

(the subfields are described right after and include pointers to how they should be filled, so I think it is ok to omit the bullet points)

  1. Emphasize "Random data to provide uniqueness as per {{unguessability}} OR " in front of bullet points 1 and 2.

I am not a standards person, so perhaps there is a more elegant and/or IETF-y way to rephrase the section to deemphasize the use of the optional subfields.

@LiosK
Copy link
Contributor

LiosK commented Jun 4, 2023

How about the text like this?

UUIDv7 values are created by allocating a Unix timestamp in milliseconds in the most significant 48 bits and filling the remaining 74 bits, jointly, excluding the required version and variant bits, with random bits to provide uniqueness for each new UUIDv7 generated. Alternatively, implementations MAY fill the 74 bits with a combination of the following subfields, in this order from the most significant bits to the least, to guarantee additional monotonicity within a millisecond:

  1. An OPTIONAL sub-millisecond timestamp fraction (12 bits at maximum) to utilize extra clock precision as per {{monotonicity_counters}} (Method 3).
  2. An OPTIONAL carefully seeded counter to guarantee additional monotonicity as per {{monotonicity_counters}} (Method 1 or 2).
  3. Random data for each new UUIDv7 generated to provide uniqueness for any remaining space.

I totally agree that the emphasis should be given to the random data because the extra clock precision and monotonic counter are absolutely optional. I'm concerned about removing the bullets because the Monotonicity and Counters section isn't really intuitive, and thus it looks hard for readers to determine what is actually permitted in implementing a UUIDv7 generator. The subfield description should be helpful to clarify that point.

@LiosK
Copy link
Contributor

LiosK commented Jun 4, 2023

Tweaked the proposed text to reduce repetition:

UUIDv7 values are created by allocating a Unix timestamp in milliseconds in the most significant 48 bits and filling the remaining 74 bits, jointly, excluding the required version and variant bits, with random bits for each new UUIDv7 generated to provide uniqueness as per {{unguessability}}. Alternatively, implementations MAY fill the 74 bits with a combination of the following subfields, in this order from the most significant bits to the least, to guarantee additional monotonicity within a millisecond:

  1. An OPTIONAL sub-millisecond timestamp fraction (12 bits at maximum) as per {{monotonicity_counters}} (Method 3).
  2. An OPTIONAL carefully seeded counter as per {{monotonicity_counters}} (Method 1 or 2).
  3. Random data for each new UUIDv7 generated for any remaining space.

@fboulnois
Copy link
Author

Tweaked the proposed text to reduce repetition:

UUIDv7 values are created by allocating a Unix timestamp in milliseconds in the most significant 48 bits and filling the remaining 74 bits, jointly, excluding the required version and variant bits, with random bits for each new UUIDv7 generated to provide uniqueness as per {{unguessability}}. Alternatively, implementations MAY fill the 74 bits with a combination of the following subfields, in this order from the most significant bits to the least, to guarantee additional monotonicity within a millisecond:

  1. An OPTIONAL sub-millisecond timestamp fraction (12 bits at maximum) as per {{monotonicity_counters}} (Method 3).
  2. An OPTIONAL carefully seeded counter as per {{monotonicity_counters}} (Method 1 or 2).
  3. Random data for each new UUIDv7 generated for any remaining space.

This version sounds great! I agree with your earlier concerns about removing the bullet points completely. Thanks for revising the text so quickly.

@LiosK
Copy link
Contributor

LiosK commented Jun 4, 2023

Crafted a PR. Let's see if everyone is okay with it.

Perhaps, I tend to construct unintuitive if logically correct paragraphs. Thank you for your great feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants