Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In distributed systems, you can easily deal with this by assigning each client node an ordinal, and the client generates a sequential id that is a multiple of the highest ordinal of the ring added to the client's local ordinal. You can synchronize ordinal values between nodes with something like zookeeper or etcd.


If you're having to synchronize it using a strongly consistent mechanism, couldn't you just use an auto-incrementing integer anyway (not meaning to be snarky here - I legitimately don't know)? The benefit of a UUID is you don't need strong consistency; even on a partition of < n+1 nodes you can still generate IDs, and even if the network is unpartitioned, you can generate an ID without making a roundtrip.

I would also debate your use of the word 'easily'; what's easier, setting up zookeeper/etcd, or just generating a UUID?

But yes, if your use case is "I want to make sure I have non-conflicting IDs across my cluster", synchronizing them is a possible solution. And the right one, if your requirements stipulate absolute ordering based on the generation of each ID.


You would need to synchronize less often and that can be big benefit performance wise. i.e. you can tolerate more partitions without effects. If done right and in some cases you can have the same benefits as UUIDs with smaller keysizes.

After all UUIDs only make it unlikely that you have conflicting IDs not impossible. Especially if your random source is not that random.


You will never in your lifetime find a collision if you use v4 UUIDs generated from a CPRNG such as /dev/urandom. No one will.


Yes, key being, if your source is not that random i.e. programming errors.


Auto-incrementing using some kind of centralized store is synchronous, UUID generation is asynchronous.


In which case, you could equally use v1 or v5 UUIDs.

Plus a UUID can be generated by a source outside your network -- eg, client side, with the ability to treat them as quasi-nonces for replay detection.

Or inside your network, during long-running partitions.

The bigger question is: why would I install, manage, update, monitor zookeeper/etcd and write my own custom ID generator and all the storage mechanisms around it, when I can just use UUIDs?


Right, but I'm addressing the parent case in which ordered id is required (for whatever use case)


v1 UUIDs are ordered.


Our clients come and go and are largely unknown to us. Even in that case what you are describing is UUID1.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: