Age Apache
Age Apache

Reputation: 1

How to store history of an edge in graph database?

I am designing a way to store history of a graph in a graph database. I have the following in mind:

History of a node, say Vertex_A, is maintained by creating another history node, say History_Vertex_A. Whenever Vertex_A is modified, a new version node, say Vertex_A_Ver_X, is created. This new node stores the old values of the changed data. A new edge is created between the history node and the version node. Following diagram depicts this idea. Is there a better way to store history of a vertex/node in a graph database?

                                +------------------+
                                | Vertex_A (Ver N) |
                                +---------+--------+
                                          |
                              +-----------v-----------+
                              | Edge_Vertex_A_History |
                              +-----------+-----------+
                                          |
                                +---------v--------+
                                | History_Vertex_A |
                                +---------+--------+
                                          |
         +---------------------+----------+----------------+----------------------+
         |                     |                           |                      |
  +------v-------+      +------v-------+          +--------v-------+      +-------v--------+
  | Edge_A_Ver_0 |      | Edge_A_Ver_1 |          | Edge_A_Ver_N-2 |      | Edge_A_Ver_N-1 |
  +------+-------+      +------+-------+          +--------+-------+      +-------+--------+
         |                     |                           |                      |
+--------v---------+  +--------v---------+      +----------v---------+  +---------v----------+
| Vertex_A (Ver 0) |  | Vertex_A (Ver 1) | .... | Vertex_A (Ver N-2) |  | Vertex_A (Ver N-1) |
+------------------+  +------------------+      +--------------------+  +--------------------+

Now, say I have the following relation. Vertex_A is connected to Vertex_B via edge Edge_AB.

+----------+      +---------+       +----------+
| Vertex_A +------> Edge_AB +-------> Vertex_B |
+----------+      +---------+       +----------+

I can store the history of vertices as per the above design, but I cannot use that same idea to store history of edges, edge Edge_AB in this case. This is because it won't be possible to have an edge connecting to it's corresponding history vertex. An edge cannot connect to a vertex. So what is the best way to store history of an edge in a graph database?

Upvotes: 0

Views: 283

Answers (1)

Wey Gu
Wey Gu

Reputation: 631

Your approach is universally working among different graph databases.

One more approach that we are doing with NebulaGraph is to leverage the rank concept in its edge defination.

In NebulaGraph, the factor to define one instance of an edge is: [src, dst, edge_type, rank], where the rank is an int to represent things like transaction_id, timestamp, version or whatever generates multiple between two vertices in one edge type.

note, rank field could be ommited, where the value will be 0, thus it brings nothing new to us with same mind model from other graph databases when using it.

With rank, we could easily design the versioning of edges here. But how could we design the versioning of vertecies then? Our approach will be to introduce an edge with dst-vertex of itself, and put the propertis that could differ from different versions of vertices in this edge, where the rank is the version and the properties are on the edge.

ref:

Upvotes: 0

Related Questions