Adding a new vertex and edge in high concurrency environment


Using SQL on ODB 2.2 or 3.0, I have an application that will frequently add a new vertex and a new edge from an existing vertex to the new vertex. This has a high likelihood of happening simultaneously from multiple clients (it is a high concurrency environment). But if client A creates the new vertex and the new edge, and client B comes along right after, client B does not need to create the new edge or vertex (it simply needs to follow the edge and operate on the new vertex).

I have to create the new vertex first, since I can’t create an edge between two vertexes until both of them exist. But until the new edge is created, client B would have no way to know that the new vertex exists. So what would prevent client B from just creating its own “new” vertex and edge?

So the question is: What is the best way to allow “the first” client to create the new edge and vertex and letting “the subsequent” clients simply use what the first client has already created, considering that all clients would be capable of creating the new vertex and edge if it doesn’t already exist?

Note, too, that this is a simplified example. The real use-case is that “the first” client would potentially create a set of new vertexes and a “chain” of edges linking them all.


Hi @eric24

I’d say the topic here is to identify a vertex un a unique way, so that two clients do not create it concurrently. The creation of the edge is just a consequence and comes easy as long as you are sure you do not have duplicate vertices.
IMHO you just have to add an application key property to the vertex, define a UNIQUE index on it and rely on unique constraint violation to avoid duplicates




@luigidellaquila: Yes, that makes sense. Let me play around with that.


Is there a way that we can obtain the last insert id like in php in order to work with it??