Hacker News new | ask | show | jobs
by xwintermutex 4142 days ago
I don't understand this sentence: "One caveat to the randomness is that in order to preserve chronological ordering if a client creates multiple push IDs in the same millisecond, we just ‘increment’ the random bits by one."
2 comments

If you generate ids like:

    <fixed width timestamp><random data>
Your ids are guaranteed to be sorted chronologically until you start generating them at the same time. So as a hack to work around that they generate:

    <fixed width timestamp><fuzzed random data>
Where the fuzz to the random data ensures that it's sorted chronologically.
The ID consists of a timestamp to millisecond precision and a random value. Since the timestamp only offers millisecond precision, two IDs generated in the same millisecond could be out of order depending on the random value because the timestamps will be the same. In order to prevent that, if two IDs are generated in the same millisecond, instead of generating a new random value, they take the random value from last time and add 1. This ensures that even though the timestamp of the second ID is the same as the first one, it will sort after the first one.
I see, thanks!