broofa/node-uuid — Issue #32: Implement k-ordered IDs a la Flake
Author: mhart
Created: 2012-01-24 05:22:55+00:00
State: open

Take inspiration from:

https://github.com/boundary/flake

"Flake ids are 128-bits wide described here from most significant to least significant bits.

64-bit timestamp - milliseconds since the epoch (Jan 1 1970)
48-bit worker id - MAC address from a configurable device
16-bit sequence # - usually 0, incremented when more than one id is requested in the same millisecond and reset to 0 when the clock ticks forward

UUID-1 is an odd beast. First, the timestamp is based on the number of 100 nanosecond intervals since October 15, 1582. This is not how most of us familiar with Unix timestamps reason about time. If that isn't bad enough, the timestamp is an odd 60-bits in length with the most significant bits shifted to the least significant bits of the UUID. This property makes lexical ordering essentially meaningless. The remaining bits contain a clock id (initially set to a random number) and a node id (usually the MAC address).

The first problem is the timestamp. We could rearrange the bits to get some k-ordering love, but reasoning on timestamps of this nature makes reasoning about the resulting ids more complex than it needs to be. This is why flake uses a standard 64-bit Unix timestamp, unaltered, as the most significant bits."

I realise that this project is focused on UUIDs as defined in RFC4122, so this sort of ID generation wouldn't fit within that goal - but I hadn't seen a similar Node.js project as yet and thought I'd check to see if you wanted to implement it here.