You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm just wondering, did you find a monotonic strict increasing clock source for the timestamp generation? Otherwise there's a small change at high resolution scenarios where the time will be the same, we could get an equal time and then the ids are not strictly ordered. Compare with: https://github.com/boundary/flake And with reference to: http://learnyousomeerlang.com/time
On a single machine it should be possible with just a counter though, but then you need to keep state of the old counter somewhere. If the OS could provide this counter, it would be much easier.
You're completely correct, at high resolution scenarios, there is a chance of non-strict ordering. I think for this library, a state variable will be the most appropriate for ensuring monotonicity. Is this something you'd like to add?
@alizain I think I have a related question: in the case where we do have strictly ordered items (say a batch of items to be processed), an increasing counter for that batch would provide ordering. What would you think about making the first 16 bit uint an optional random or counter? In that case the layout might look like:
Yes, I used a private counter variable, ended up being pretty straightforward.
I've spec'ed out the way it achieves monotonic. If there are no flaws, than ideally, other implementations would simply follow that spec. I think for specific languages, it would be best to create issues in that project, where you require this feature.
As you can see, the same time component is being passed into the generator. To preserve ordering, it increments the least significant bit in the random component (with carrying for overflows).
Activity
alizain commentedon Mar 30, 2017
You're completely correct, at high resolution scenarios, there is a chance of non-strict ordering. I think for this library, a state variable will be the most appropriate for ensuring monotonicity. Is this something you'd like to add?
phillbaker commentedon Apr 19, 2017
@alizain I think I have a related question: in the case where we do have strictly ordered items (say a batch of items to be processed), an increasing counter for that batch would provide ordering. What would you think about making the first 16 bit uint an optional random or counter? In that case the layout might look like:
CMCDragonkai commentedon Apr 20, 2017
In PHP, you need one of 2 extensions, the one that gives you the posix monotonic clock, or the one that gives you windows monotonic clock.
alizain commentedon Oct 24, 2017
Monotonically increasing ULIDs have been spec'ed and implemented, so I'm closing this. Let me know if there are any issues!
CMCDragonkai commentedon Oct 24, 2017
How did you decide to implement it? With a private counter variable? I guess that's more portable than relying on the OS monotonic clocks.
Also how can we propagate this functionality to all the other implementations?
alizain commentedon Oct 24, 2017
Yes, I used a private counter variable, ended up being pretty straightforward.
I've spec'ed out the way it achieves monotonic. If there are no flaws, than ideally, other implementations would simply follow that spec. I think for specific languages, it would be best to create issues in that project, where you require this feature.
alizain commentedon Oct 24, 2017
@CMCDragonkai and @phillbaker, to illustrate the implementation, I've copied over some code from the README.md
As you can see, the same time component is being passed into the generator. To preserve ordering, it increments the least significant bit in the random component (with carrying for overflows).