DEV Community

Discussion on: What would you use as a sortable, globally unique, ID?

Collapse
 
johanneslichtenberger profile image
Johannes Lichtenberger
Collapse
 
rhymes profile image
rhymes • Edited

Something like the Twitter Snowflake generator

The problem with the Snowflake generator is in its definition. It's a server that nodes have to sync up to, which would require a node that needs to be monitored, load balanced and so on, only to generate IDs. Also, if one day we want the clients to be able to generate their own IDs to send to the server the Snowflake would be an architectural limitation.

I think if works for Twitter but for example in the article you linked they mention this problem.

I'm not comfortable about the implementation in the article because it uses the MAC address which is one of the issues with the earlier versions of UUIDs but maybe something like Firebase does is better: firebase.googleblog.com/2015/02/th... - moving away from using an hardware identifier like the MAC even if they are not perfect. I think ULIDs are better github.com/ulid/javascript

Thread Thread
 
johanneslichtenberger profile image
Johannes Lichtenberger

I thought Snowflake wouldn't require a central server, why would it? Haven't read the stuff now but a few years ago.

As mentioned in the second article it uses a timestamp + nodeID + sequenceID. The sequence-ID might be the same, but the nodeIDs could be anything which identifies the server uniquely I guess. Okay, finding something which is unique with only using qafew bytes, I don't know...

Thread Thread
 
rhymes profile image
rhymes

I thought Snowflake wouldn't require a central server, why would it? Haven't read the stuff now but a few years ago.

I don't know about the latest incarnation, but the one that was public years ago was a server generated with Apache Thrift and used ZooKeeper for coordination. Not exactly practical unless you're Twitter...