Sequential Global Business ID for each node

Hi All,

I am converting a (let's say relational) system into Neo. In the current system, we generate a unique ID for each new row. The ID is only 5 digits, alpha numeric e.g. '01BJF' and is generated sequentially (the next id would be '01BJG') and is globally unique across all types of rows. This Id is also immutable on each row and the IDs are not re-used.

Moving across to Neo4j, I know I could easily use GUID's as the ID on new nodes however our business folks have become very attached to their 5 digit ID's and they are rolled into all sorts of fixed length identification and accession numbers and printed on test tubes etc... so we need to keep them.

In Neo4j, I can only see 2 options.

  1. Use a custom IdStrategy - I have no idea where to start with this... is this a procedure?
  2. Generate the ID outside of Neo4j and add it as a business/natural ID to nodes when they are added (so each node would have an autogenerated node ID and a 5 digit business ID).

In both cases, I think I would need to store the 'last ID generated' in some sensible global place (maybe as a property on a single utility node?) and increment this when I generate the next one or many ID's.

Any help appreciated with this. Which of my options is simplest? where would I store my 'last ID generated'? have I got this completely wrong?


Hi Michael,

welcome to the Neo4j community!
Interesting task you got there. When reading your post, I also directly thought about a mix of the solutions that you suggested yourself. So, what I would do is:

  • save the most recent ID in an auxiliary node
  • write a user defined function in Java that obtains the most recent ID as an input and outputs the next ID
  • call the procedure when nodes are created.

To maybe give you a better insight in how that would work, here are some code bits that I have in mind:

1 - The user defined function would be called something like that:

MATCH (i: IdNode)
CREATE (b:Business) 
SET b.businessId = myProcedure.getNextId(

2 - The user defined function would then be something like

public Long getNextId(Long id){
return newId;

I hope this helps you.

Thanks for the feedback Elena, this is very helpful and aligns perfectly with what I was thinking. Great minds think alike ;)


Hi @elena_kohlwey I have this working now.. thanks for the feedback. One thing though in your response, you didn't update the id node...this is what I am doing roughly

MATCH (i: IdNode)
SET = myProcedure.getNextId(
CREATE (b:Business) 
SET b.businessId =

So I'm updating the Id node in place, then using the updated id value in my create

Yep, sounds good. Of course it needs to be updated :-).