Are uids guaranteed to be incremental?

I want to order records based on creation order.
To do so, I want to use uid since it is the default ordering.

I wonder if uid of a record inserted after another can be less than previous record’s uid?

Can I assume uids are always incremental?

Always strictly increasing, yes. Though, they could have jumps in their sequence, as in after handing out 100, we could hand out 110.

I think this is a really important fact and this should be boldly announced in the docs page.
As far as I know, Neo4j uids are volatile and can change in time.
All software written with Neo4j must govern their own uids for this reason.

This is a great +points for Dgraph against Neo4j.
I hope this is the design principle and will never change, so development would rely on this fact
This is an advantage and can be used for marketing as well.

Thank you for quick response!

https://neo4jrb.readthedocs.io/en/9.1.x/UniqueIDs.html

The database generates unique IDs and they are accessible from all nodes and relationships using the neo_id method. These keys are somewhat volatile and may be reused or change throughout a database’s lifetime, so they are unsafe to use within an application.

We have had this since the early days of Dgraph. It’s not going to change.

Also, there’re many things about Dgraph which are better design choices than other graph DBs. That’s what lets us focus on making Dgraph a general purpose primary DB to compete with top of the line SQL or NoSQL DBs.

3 Likes

In addition to this,
It would be really nice ,
if I can list records with descending order by uid.
Now we can’t.
I think it is implementable with not much pain.

func: (orderdesc: uid)

What would the usecase of ordering by UID be?

Is this like a shorthand for order by created-datetime?

A uid is just a number representing a graph. We happened to pick numbers because it is ℵ0.

Exactly, it is really great use case. Really common.
Since uids are first class citizens, by adding orderdesc: uid support,
several queries will get rid of order by predicate parts.

Another use case: Today, I wanted to get last uid of a Type and just because of it I need to add an order over new predicate.