Footsteps in the sand, the seashore mind…

Gremlin vs Cypher Initial Thoughts @Neo4j

The Neo4jClient now supports Cypher as a query language with Neo4j. However I noticed the following:

Simple graph traversals are much more efficient when using Gremlin

Queries in Gremlin are 30-50% faster for simple traversals

Cypher is ideal for complex traversals where back tracking is required

Cypher is our choice of query language for reporting

Gremlin is our choice of query language for simple traversals where projections are not required

Cypher has intrinsic table projection model, where Gremlins table projection model relies on AS steps which can be cumbersome when backtracking e.g. Back(), As() and _CopySplit, where cypher is just comma separated matches

Cypher is much better suited for outer joins than Gremlin, to achieve similar results in gremlin requires parallel querying with CopySplit, where as in Cypher using the Match clause with optional relationships

Gremlin is ideal when you need to retrieve very simple data structures

Table projection in gremlin can be very powerful, however outer joins can be very verbose

So in a nutshell, we like to use Cypher when we need tabular data back from Neo4j and is especially useful in outer joins.

Here are two queries that return the exact same data from Neo4j, one in Cypher and one in Gremlin.