Azure Cosmos Gremlin API: transactions and efficient graph traversal

459 Views Asked by At

We are experimenting with the Cosmos Gremlin API because we are building a large scale knowledge-management-system which is naturally suited for a graph DB. Knowledge items are highly interconnected and therefore a graph is much better than a relational or a document-oriented (hierarchical) structure. We need atomic write operations (not full transaction support, just atomic writes). E.g. we need to create several vertices and edges in one atomic write operation.

After carefully reading the documentation and extensively searching for solutions, our current state of knowledge is following:

  • Cosmos Gremlin API stores vertices as documents and outgoing edges as part of the "outgoing document".

  • A Gremlin statement creating vertices and egdes might be split up and executed in parallel.

  • There is no transaction support and there are no atomic write operations.

    • Write operations are not idempotent.
    • The two facts taken together mean: If you execute a graph write operation and an error occurs somewhere along the traversal, you have no chance whatsoever to recover from it in a clean way. Let's say you add an edge, add some vertices, perform some side-effect-steps and something goes wrong. Which vertices and edges are persisted and which are not? Since you cannot simply run the statement a second time (vertices with the ids already exist), you're kind of stuck. In addition, this is nothing which can be solved on the end-user-level in the UI.
    • Taken this points into account, it seems, that the Cosmos Gremlin API is not ready for a production app. When you have a look at the Gremlin "data explorer" in the portal, that seems even more true. I looks like a prototype.
  • Since edges are stored on the "outgoing document", one should always traverse the graph using the outgoing edges, not the incoming.

    • This takes away a lot from the efficiency of working with a graph DB: To traverse both directions efficiently.
    • It leads to workarounds: For each outgoing edge, create an "inverse edge" on the incoming vertex.

So I'd like to ask the question: Should one use Cosmos Gremlin API in production? So far I haven't seen or read about anyone who does so.

1

There are 1 best solutions below

0
On

Write operations are not idempotent.

It is possible to write queries in an idempotent way however it's not really done in a nice readable and maintainable way. See an idempotent gremlin example here: https://spin.atomicobject.com/2021/08/10/idempotent-queries-in-gremlin/

Taken this points into account, it seems, that the Cosmos Gremlin API is not ready for a production app

This really depends on your application requirements, not all production applications require atomicity or transactions. Sometimes some systems can drop data or if needed you can do various things to ensure data integrity - Though this often puts more responsibility of the application developer

So I'd like to ask the question: Should one use Cosmos Gremlin API in production? So far I haven't seen or read about anyone who does so.

I haven't seen too many stories of using it in production anecdotally, it looks like CosmosDB is relatively popular but hard to tell what proportion of users are running which API.