DEV Community

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

Collapse
 
yaser profile image
Yaser Al-Najjar • Edited

I love simplistic solutions, here is my 0.2 cents:

Use a prefix for each node like n1 / n2

Generate an incremental ID: 1, 2, 3...

So you will end up with IDs like:

n1-1
n1-2
n2-1
n2-2

Easy to sort and never gonna conflict.

Does that help with your use case?

Collapse
 
rhymes profile image
rhymes

Not exactly, what if the node is a client and for any reason they set the same name? What if the node changes name or is replaced by another one?

Aside from the sortable part, the problem of conflict is already solved by using UUIDs, going back to incremental IDs is not feasible in this case.

Unfortunately this, as many things in distributed systems, is not that simple.

Collapse
 
yaser profile image
Yaser Al-Najjar

I get it.

You wanna have a long-term solution, however, you still didn't tell us your exact use case so we are throwing bunch of out-of-context solutions.

BTW, this might be a very interesting solution (using both UUID and incremental ID): tomharrisonjr.com/uuid-or-guid-as-...

Thread Thread
 
rhymes profile image
rhymes • Edited

You wanna have a long-term solution

I think this is one of those few cases when there's no cost into having a correct long term solution instead of having to change the format of IDs (and thus having multiple sets of them) in time.

you still didn't tell us your exact use case so we are throwing bunch of out-of-context solutions.

I didn't write the final goal explicitly but I wrote the requirements. The final goal is to traceable unique IDs for events in a distributed system that also are sortable which is a very handy property. There's no mistery to it :D

BTW, this might be a very interesting solution (using both UUID and incremental ID): tomharrisonjr.com/uuid-or-guid-as-...

I agree that exposing IDs is not great, not even UUIDs in theory. In that case is best to have multiple keys.

It's an interesting approach but it's tied to a database. I want something that would work at each level (the programming language, the DB table, an event log and so).

Thanks for sending me suggestions though, it's really great to see all of these approaches!!