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

Improve id to support microseconds #1

Open
eldoy opened this issue Jul 19, 2024 · 0 comments
Open

Improve id to support microseconds #1

eldoy opened this issue Jul 19, 2024 · 0 comments

Comments

@eldoy
Copy link
Owner

eldoy commented Jul 19, 2024

Ok, but does it always work even if we're running a million requests in parallel on a multi-CPU system?

I did read that CUID wasn't the best for this, it's a k-sortable, which only has guarantees on less than 10 000 items, and the guy who wrote the lib recommended using created_at instead. When I tried with created_at it wasn't always working though, I guess the date isn't precise enough as it's only milliseconds.

https://github.com/paralleldrive/cuid?tab=readme-ov-file#monotonically-increasing-ids

Maybe it's overkill, but the fix should be easy enough. Using this as id stores time in microseconds:

var id = process.hrtime.bigint()
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

No branches or pull requests

1 participant