Author Archives: maxdemarzi

Dynamic Rule Based Decision Trees in Neo4j – Part 2

A couple of weeks ago I showed you how to build a dynamic rule based decision tree in Neo4j. It was pretty simple and used an Expression Evaluator to determine if a set of parameters in an expression was true or false. Based on that answer it decided where to go.

But what if we had more than just true or false? What if we wanted to make our Rule nodes have more than 2 options? Today I am going to show you how to do just that… but please make sure you have read part 1 already.

Continue reading

Tagged , , , , , , , ,

Neptune and Uranus

Last year Microsoft announced “Cosmos DB”, a multi-modal database with graph support. I think multi-modal databases are like swiss army knifes, they can do everything, just not very well. I imagine you would design it to be as good as it can be at its main use case while not losing the ability to do other things. So it’s neither fully optimized for its main thing, nor very good at the other things. Maybe you can do pretty well with two things by making a few compromises, but if you try to do everything…it’s just not going to work out.

Can you imagine John Rambo stalking his enemies with an oversized swiss army knife? Here, let me help with the mental image:
Continue reading

Tagged , , , , , , , ,

Dynamic Rule Based Decision Trees in Neo4j

A few posts ago I showed you how to build a Boolean Logic Rules Engine in Neo4j. What I like about it is that we’ve pre-calculated all our potential paths, so it’s just a matter of matching up our facts to the paths to get to the rule and we’re done. But today I am going to show you a different approach where we are going to have to calculate what is true as we go along a decision tree to see which answer we get to.

Yes, it will be a bit slower than the first approach, but we avoid pre-calculation. It also makes things a bit more dynamic, as we can change the decision tree variables on the fly. The idea is to merge code and data into one, to gain the benefit of agility.

Continue reading

Tagged , , , , , , , , , , ,

Adding gRPC to Neo4j

You are probably sick of me saying it, but one of the things I love about Neo4j is that you can customize it any way you want. Extensions, stored procedures, plugins, custom indexes, custom apis, etc. If you want to do it, then you can do it with Neo4j.

So the other day I was like what about this gRPC thing? Many companies standardize their backend using RESTful APIs, others are trying out GraphQL, and some are using gRPC. Neo4j doesn’t support gRPC out of the box, partially because we have our own custom binary protocol “Bolt”, but we can add a rudimentary version of gRPC support quite easily.
Continue reading

Tagged , , , , , , , ,

Stored Procedure to Import Data

A while back I showed you how to write an extension to import the MaxMind city data set. Today is just a repeat of that exercise but instead of using an extension, we will use a stored procedure.

The documentation spells out how to write your own procedures in Chapter 6 so I’m not going to go over that again, but I do want to point out a few things.
Continue reading

Tagged , , , , , , , , ,

Mutual Fund Benchmarks with Neo4j

Just the other day I had a conversation with an Investment Risk Manager about one of the data problems his team was working on and he was wondering if Neo4j could help. Imagine you have about 20,000 mutual funds and etfs and you want to track how they measure up against a benchmark like say the returns of the S&P 500. I’m sorry did I say one? I meant all of them, let’s say 2,000 different benchmarks… and you want to track it every day, for a rolling 5 years period. So that’s 20,000 securities * 2000 benchmarks * 5 years * 252 trading days a year (on average)… or 50 billion data points. That’s a BIG join table if we were using a relational database. How can we efficiently model this in Neo4j?
Continue reading

Tagged , , , , , , , ,

Bill of Materials in Neo4j

Where is da BOM? The above question asks, and the obvious answer is right in the middle of your organization. Nestled between Manufacturing, Design, Sales and Supply Chain. But I have a better answer. Your Bill of Materials should be in Neo4j. Today, I’ll show you why.
Continue reading

Tagged , , , , , , , , , ,

Counting Nodes with Multiple Labels

We have over 6000 users in our #neo4j-users slack channel and get all kinds of requests. About a month ago Thomas Shields asked:

Should counting the set of things with 2 labels really take so long? I’ve got 48M nodes with LabelA and LabelB and the query `MATCH (n:LabelA:LabelB) RETURN COUNT(n)` is taking 80-90 seconds

Let’s see what’s going on by creating a small version of his graph. We will create 1M nodes of LabelA, then 1M nodes with both LabelA and LabelB, and then 1M nodes with just Label B:
Continue reading

Tagged , , , , , ,

Work Order Management with Neo4j

I look terrible in a bikini (take my word for it) but I’d love me a Lamborghini. However, in order to afford nice things, we need to do as the song says and get to work…and we need to manage and prioritize that work somehow. Today, I’m going to show you how to build part of a work order management system with Neo4j.

I’m going to build an evented work order model. So let’s say our Order gets created, then based on what it is, pieces of Work need to happen. This work is performed by some Provider (whether internal or external) and that work can be broken down into Tasks that have dependencies on Events that have occurred. How would this look like in the graph? Glad you asked:
Continue reading

Tagged , , , , , , , , , , ,

Building a Boolean Logic Rules Engine in Neo4j

A boolean logic rules engine was the first project I did for Neo4j before I joined the company some 5 years ago. I was working for some start-up at the time but took a week off to play consultant. I had never built a rules engine before, but as far as I know ignorance has never stopped anyone from trying. Neo4j shipped me to the client site, and put me in a room with a projector and a white board where I live coded with an audience of developers staring at me, analyzing every keystroke and cringing at every typo and failed unit test. I forgot what sleep was, but managed to figure it out and I lost all sense of fear after that experience.

The data model chained together fact nodes with criss crossing relationships each chain containing the same path id property we followed until reaching an end node which triggered a rule. There were a few complications along the way and more complexity near the end for ordering and partial matches. The traversal ended up being some 40 lines of the craziest Gremlin code I ever wrote, but it worked. After the proof of concept, the project was rewritten using the Neo4j Java API because at the time only a handful of people could look at a 40 line Gremlin script and not shudder in horror. I think we’re up to two handfuls now.
Continue reading

Tagged , , , , , , , , , ,