Hi Neo4j followers and experts,

I have been thinking about how to model entities with versions in Neo4j a
few times, but never had opportunity to implement such a thing. Now I find
myself in a project where every version of everything is relevant. It turns
out that the actual structure needed for the version management is not

I feel that this is something that would occur in more applications, so I
thing that it would be a good idea to come up with, and document, a design
pattern for how to model different versions of entities in Neo4j. I would
love to get ideas from anyone on this, especially if you have implemented
something like this, but even if you just have ideas it would be great to
hear them.

If you are modeling a perfectly hierarchical structure of versioned entities
(such as a VCS), you can copy-on-modify each modified entity and it's
parent. Something like this:

/ v1:
 - foo/ v1:
  - foofile v1
  - bazfile v1
 - bar/ v1:
  - barfile v1

Change to foofile results in:

/ v2:
 - foo/ v2:
  - foofile v2
  - bazfile v1
 - bar/ v1: ...

Getting a versioned entity would in this case start traversing from the root
for the desired version, and thus find the correct version for the desired
entity. Each entity node would also have a relationship to the node
representing the previous version of that entity, forming a linked list of
versions for each entity. For the root this would be used to find a specific
version, before traversing out the deisred resource. It can also be used to
compute differences between versions of an entity.

But what about the case when the structure is an actual graph (as opposed to
a tree), or for some other copying *all* relationships and properties would
be too expensive. It could be possible to only add the diff to the new
version node, but how do you model removal? For properties you could
overwrite with a default value, or store a sentinel, but how to model that a
relationship has been removed from version to another without copying all of

Any ideas on how to model entity versions? Any comments on my draft
structures? Any input is valuable! Let's nail a pattern for modeling
versioning, and get it into the wiki.

Tobias Ivarsson <tobias.ivars...@neotechnology.com>
Hacker, Neo Technology
Cellphone: +46 706 534857
Neo mailing list

Reply via email to