At GraphAware, we live and breathe Neo4j. For three years, we have been helping customers around the world embrace this amazing technology as a solution to many interesting problems. Mainstream applications of graphs, such as real-time recommendations, fraud detection, impact analysis and graph-aided search have been getting a lot of media attention.

In the run up to GraphConnect Europe, we would like to illustrate that graphs are truly for everyone by going over some of the less obvious, though equally interesting and intellectually stimulating use cases that we have come across.

Rules Engines

Whether you’re a startup building a mobile application that will help people diagnose their medical condition, or a large retailer trying to decide which carrier to book a shipment with, you will need a computer program to interpret a set of potentially complex rules in order to determine an outcome, given a set of known initial conditions.

These rules will likely change too fast for the development teams to keep up, even in the most agile of environments. Moreover, it is typically the business, not the development teams, who define the rules.

A data-driven, rather than code-centric approach is needed, where rules can be loaded from a database and interpreted at runtime. To achieve this, we believe there is no better data model than a graph.

Learn about Less Common Use Cases for Graph Databases including Law Enforcement and Rules Engines

The image above shows a simple set of rules and point-based outcomes to help decide whether a person should attend GraphConnect in London. This graph can be understood by people with very little technical background, who would be able to tell just by looking at it that a person should attend the conference if they live in London or are a frequent traveller, but not if they are under the age of 18 or uninterested in technology.

For a developer, it would be equally easy to develop a simple application that interprets these rules and provides a decision for any given input. With this in place, business logic can be changed by adding, removing or updating rules directly in Neo4j.

With a working graph-based rules engine like this, a business user can decide in microseconds which shipping route to take based on the characteristics of a package or which supplier to use based on the requirements of a customer.

Intelligence and Law Enforcement

Let us now take a look at another important, yet not often publicised use for graphs. Criminals, terrorists and other “bad guys” have two things in common.

The first one is that they pose a greater threat when they are organised, i.e., they form some sort of a network. The second is that they leave traces of their activity, no matter how sophisticated they are.

Graph databases are a great tool for uncovering and investigating illegal or otherwise malicious activity for three main reasons. First, they are easy to query and navigate using the Cypher query language and available visualisation tools, even for non-developers. Second, they are very fast at analysing connected data. Hence, answers can be found very quickly in critical situations, such as during an ongoing terrorist attack. Finally, and perhaps most importantly, graphs help users discover the “unknown unknowns”.

Imagine you’re the investigator of a crime and all the clues you have are a credit card transaction and a car license plate. The first question you would most definitely want to answer first is whether these clues are in any way related and how.

Without a graph database, you will have to start by enumerating all the ways these clues could be related. Even if you were able to do that, the resulting query would likely be very complicated.

In Neo4j, finding the answer could be as simple as this Cypher query:

MATCH p=(tx:Transaction {txId:'123abc'})-[*..10]-(c:Car {plate:'LOVE NE04J'})

Without any up front knowledge about how the two may be related, you could find out, for example, that the card was used to pay for a speeding fine for the car and that it belongs to Alice, the sister of Bob who owns the vehicle.

A Graph Database in a Law Enforcement Use Case

See You at GraphConnect Europe

There are a plethora of other compelling use cases. We have used graphs to design complex university curricula, analyse investment portfolio risks, audit systems and even generate storylines that will appeal to an audience.

The possibilities of graphs are endless. Come meet us at GraphConnect to chat about how Neo4j can help you, no matter how niche your domain or particular problem. As always, the GraphAware conference stand will be a lot of fun! We look forward to meeting you soon.

GraphAware is a Silver Sponsor of GraphConnect Europe. Click below to register for GraphConnect and meet Michal and the rest of the GraphAware team in London on 26 April 2016.

Get My Ticket



About the Author

Michal Bachman , Managing Director, GraphAware

Michal Bachman Image

Michal Bachman is the Managing Director at GraphAware, where he leads a team of Neo4j Certified Professionals who help clients around the world succeed with graphs. Michal is the main committer to the GraphAware Framework, a set of open source tools and extensions to Neo4j, and the author of the GraphAware Recommendation Engine library.


Marcel says:

You wet my appetite with the rules section, only to disappoint by not giving details. Showing the rules is all very nice, but I could do that with paper and pencil. It would be more interesting if you could show how to enter rules in a graph and, given some initial data, have cypher queries act as the rules engine to obtain decisions.

Even more interesting, could cypher be used to optimize the process? Say that one has some rules that depend on, say, age, and the age is known (at some point in time). Could all rules that depend on age be taken into account automatically, so that less rules remain? Hmm I don’t think I’m expressing myself very clearly… I think what I’m trying to ask: what role could cypher play in a rules engine?

Hi Marcel,

Together with Michal we designed, developed and implemented a complete rules engine atop Neo4j for a customer. I can’t share the complete code of course but I can feed a bit your appetite.

I will take a simple example where you have a multiple routes possible from London to Manchester. If you would be designing “As a User, I want to find the less costly route to Manchester (no toll then)”.

You can think that all routes from London to Manchester are valid, but will have at the end a different score based on the rules the user defines and some fixed rules (for example, if there are currently road works on one of the routes, you can have these as fixed rules)

Rule Nodes can be inserted in the graph, where they connect to your domain. Therefore you can have a scoring strategy on these rules by playing with relationship types, relationship properties and different labels on the Rule Node itself.

When you will find the paths from London to Manchester for the user, you can calculate a score that is not only the length of the path and some distance and time calculations, but you can find all rules associated to nodes in these paths and apply a negative/positive score based on those rules.

An example query would be the following :

WITH {pkg:3, userPref:24} as input
MATCH p=(pkg:PkgCount {value: input.pkg})-[:SUPPORT_FRAME]->()<-[:SUPPORT_IN]-(:Service)<-[:HAS_SERVICE]-(:Box)
WITH p, nodes(p) as n, input
UNWIND n as node
WITH p, n, sum(r.value) + reduce(c = 0, y IN n | c + coalesce(y.cost, 0) ) as cost, input
OPTIONAL MATCH p2=(node)(x)
WITH p, cost, collect(p2) as ifs, input
WITH p, cost, filter(if in ifs WHERE head(nodes(if)).rule_state > head(rels(if)).value) as valid, input
WITH p, cost, reduce(tc = 0, v in valid | tc + head(tail(rels(v))).value) as tc, input,
filter(x in nodes(p) WHERE ‘SupportFrame’ IN labels(x))[0] as df
WITH p, cost, tc, input, CASE df.value WHEN input.userPref THEN 5000 ELSE 0 END as tcost
RETURN filter(x in nodes(p) WHERE ‘Box’ IN labels(x))[0] as box,
filter(x in nodes(p) WHERE ‘Service’ IN labels(x))[0] as service,
filter(x in nodes(p) WHERE ‘SupportFrame’ IN labels(x))[0] as time, cost + tc + tcost AS bestCost

Of course this is generally more complex, you can think of a rules engine as a reco/score engine and build a complete framework around it, a good start for such architecture can be taken as example in our neo4j-reco module (

Another good resource but more general to software engineering is the specifications pattern :

Concerning the role Cypher can take in the process, I’m very much thinking Cypher is the perfect query language matching the specifications pattern vision.

I invite you to get in touch by email info at and to meet us at GraphConnect if you can attend.

Kind Regards


Marcel says:

Hi Christofe,

Thanks for your response. I think that I sort of fathom were you’re going with this, but the jump to actual implementation is a little too big for me. I’ll try to formulate my use case a little better and ask again on the neo4j slack list. The above has made me look at the problem in a different way. Thanks.

Pankaj says:

Hi Christophe,

I came across this while investigating possible ways to author a business rule engine for insurance domain which traditionally have been mostly driven via XML (or in lesser cases database). Since rules engines are decision trees and trees are graphs (without loop) in my mind it seems feasible (listening to Marriott’s use case for using neo4j made the case stronger).
However I am still not able to see the clear picture thus the skepticism.

Would love to hear your thoughts on my opinion of using neo4j for authoring a database driven business rule engine which should enable business to directly add the rules.

Leave a Reply

Your email address will not be published. Required fields are marked *