-
Notifications
You must be signed in to change notification settings - Fork 116
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
feat: Support Monotonic UUIDv7
Batch Generation
#191
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a lot of added complexity to be able to generate more than one V7 UUID at a time.
// | ||
// Returns: | ||
// - GenOption: A function to configure the generator. | ||
func WithCustomPRNG(seed int64) GenOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming we move forward I think this function should be called WithExplicitRandSeed()
, or something similar, to better reflect what it's actually doing.
// | ||
// MonotonicGen ensures the generation of strictly monotonic UUIDs within a | ||
// batch by utilizing a counter in conjunction with timestamps. This is | ||
// particularly useful for applications requiring ordered identifiers, such |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for applications requiring ordered identifiers
v6 and v7 UUIDs are already ordered so none of this is strictly necessary except to enable batch generation, and I'm not sold on the utility there. I have used this library to generate UUIDs on the order of tens of millions per second sustained over 1000s of nodes in a distributed system without ever running into a scenario where I wanted/needed to pre-allocate a block of values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @dylan-bourque - I'm really not sure how useful this is relative to the increased complexity. I haven't generated millions per second, but I can't see any reason that the existing implementation doesn't do what you want. Moreover, I'm concerned that having two separate implementations of generating a new UUIDv7 (the existing public method for generating one at a time and your new private method that is called in the loop) will lead to maintenance headaches.
Is there a specific situation you have encountered in which the existing implementation fails to provide monotonically increasing values? If there is, please explain in more detail to help us understand the need.
Changes
This PR introduces a new feature for monotonic
UUIDv7
batch generation including;GenerateBatchV7
method in a newMonotonicGen
struct for batch generation.WithCustomPRNG
option for deterministic UUID generation.BY aligning with the existing library structure; this PR proposes enhanced functionality for users requiring batch UUID generation while maintaining compatibility with RFC Spec. Feedback welcome!