I got a question from one of my teams last week on how to apply versioning in Graph databases. There are multiple ways to tackle this problem but let me share the way I typically handle this.
What do you mean with ‘versioning’?
Let me start by explaining what I mean exactly with ‘versioning’. Our data changes over time. Without versioning we only now the current state of our data but not what happened in the past. By applying versioning techniques, we can keep track of changes both on the data and its dependencies. This can be useful for auditing purposes but there are a lot more reasons why this can be applied.
There are multiple types of versioning but the question I got was related to time-based versioning. The idea with time-based versioning is that you can track changes over time. We end up with an append-only model where we are able to step through time to understand the state changes.
How to model time-based versioning in graph databases?
The core idea with time-based versioning in graph databases is to separate the entity from its state. We create a separate node for the entity itself and for its state. We track the time this state was applicable through the relationship between both entity and state node.
Separate object from state
Let me further explain this by giving a small example. We start with a simple Order
node with a few properties.
What if we want to track the changes of the order over time? Let us separate the Order
entity from the OrderState
:
Now we can use the relationship to have time-based versioning. Nice!
Want to learn more?
If you want to learn more about this and other techniques, check out the following youtube video: