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

Specific Timestamp Support #13

Closed
dennisseders opened this issue Feb 24, 2024 · 2 comments · Fixed by #14
Closed

Specific Timestamp Support #13

dennisseders opened this issue Feb 24, 2024 · 2 comments · Fixed by #14
Assignees

Comments

@dennisseders
Copy link
Collaborator

In championing an upgrade for the FlakeId package, this proposal emphasizes the integration of bespoke timestamps into the Snowflake ID generation process.

The current methodology confines Snowflake ID generation solely to the current timestamp, prompting a call for sophistication. This enhancement introduces a layer of flexibility by enabling users to precisely define a timestamp, thereby amplifying the overall adaptability of the FlakeId package.

The suggested approach involves enhancing the existing Create method to gracefully accept an optional timestamp parameter, promoting consistency and simplicity in the API. This enhancement is inspired by the theoretical foundation for generating Snowflake IDs from a timestamp, as exemplified by (timestamp_ms - EPOCH) << 22 which originates from the Discord API documentation.

This proposed enhancement seeks to provide users with unparalleled control over timestamp association, aligning Snowflake ID generation precisely with their application's needs.

To incorporate this enhanced functionality, users would apply the following approach:

long id = Id.Create(timestamp);

This example showcases the simplicity and versatility that the proposed enhancement brings to Snowflake ID generation within the FlakeId package.

In conclusion, the integration of bespoke timestamps represents a significant stride towards a more sophisticated and adaptable ID generation process.

@aevitas aevitas self-assigned this Feb 25, 2024
@aevitas
Copy link
Owner

aevitas commented Feb 25, 2024

Hi Dennis,

In your use case, are you looking to migrate a bunch of data that uses non-flake IDs to Snowflakes? If so, do you have timestamps available from said original data (e.g. in a SQL column), or are you looking to pass arbitrary values as the timestamp?

Implementing this shouldn't be an issue, the current Create() call simply retrieves the timestamp from the monotonic timer. Adding an overload that accepts a timeStampMs argument or similar and uses that instead of the monotonic timestamp and updating the CreateInternal method accordingly I think is all that needs to be done.

@aevitas aevitas changed the title Bespoke Timestamp Support for Enhanced ID Generation Specific Timestamp Support for Enhanced ID Generation Feb 25, 2024
@aevitas aevitas changed the title Specific Timestamp Support for Enhanced ID Generation Specific Timestamp Support Feb 25, 2024
@dennisseders
Copy link
Collaborator Author

@aevitas That is precisely the use case upon which I have based my proposal.

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