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

feat: Support Monotonic UUIDv7 Batch Generation #191

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ashwingopalsamy
Copy link

Changes

This PR introduces a new feature for monotonic UUIDv7 batch generation including;

  • GenerateBatchV7 method in a new MonotonicGen struct for batch generation.
  • WithCustomPRNG option for deterministic UUID generation.
  • Monotonic counter handling with rollover support and timestamp management.
  • Unit tests for monotonicity, deterministic behavior and edge cases; including fuzz tests.

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!

Copy link
Member

@dylan-bourque dylan-bourque left a 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 {
Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor

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.

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 this pull request may close these issues.

3 participants