How to have a historical data in Graph Database?

Hi Team,
I was playing with the Neo4j, and came across where i have to store historical data of a Customer.
Like a Customer is Subscribed to a site with some preferences on 01-JAN-2020, and later say in 20-JAN-202 the Customer has changes his some of the preferences, and further he changed again, and currently he is having x numbers of preferences.
How to handle this?
Do we need to have a node for each changed data? if so what is the best way to have it?

Hi Mayank,

We can store any information either as node or as properties of node and it's design will be driven by the reports you need.

Regards
Vivek

Agreed with this.. but my confusion is, do we have to create another node when the property of a node changes, to maintain the history of that node, or there is any internal versioning which keeps track of any changes to properties of a node, and when required we can have it.

The behavior you are asking for would not be useful to most applications of Neo4j, but would significantly increase the resource usage for any db instance. For that reason, preserving history is not built into Neo4j.

However, there are many ways you can recover data history. Most efficiently, with Transaction Logs, but will require careful development to generate pretty views, or make nodes restorable. Alternatively, every time you change a node, you can write your Cypher to preserve the old node(s).

Your node history could be a chain of relationships:

(current)-[:PREV]->(old)-[:PREV]->(old)...

Or you could put dates/user on those relationships, and have all past versions as children of the current:

(current)-[:HISTORY {date: 'yyyy-mm-dd'; user: 'me'}]->(old)
(current)-[:HISTORY {date: 'yyyy-mm-dd'; user: 'you'}]->(old2)
// new
CREATE (old3)<-[HISTORY {date: (now); user: (self)]-(current)
SET old3 = current
SET current = new

Moral of the story, Neo4j gives you an engine, but It's up to you to make that engine do what you want it to.

1 Like