Demystifying Supply Chain management with Neo4j

Supply Chain management is very complex topic in itself, rather than focusing on details relating to Supply Chain management this blog post targets modelling it using Neo4j (a Graph Database) to answer questions like
1)Distance between retailer and wholesaler.
2)Best route to get a product involving raw manufacturer, supplier, wholesaler and retailer.

It’s natural to visualize entire supply chain as a big graph with different nodes/vertices representing sellers and products.
SupplyChain
We have different suppliers,products,wholesalers and retailers in our supply chain each represented by a vertex/node in graph (Refer to the image above)
1)All Suppliers are connected to Product they supply
2)All Products are connected to Wholesalers.
3)All Retailers are connected to Wholesalers for specific product they sale.

Graph Database are very natural choice for this kind of data, as all the data is interrelated to each other with some relationship and Graph DBs store these relationships as in , like pointers on disk avoiding any lookup and disk seek. Modelling these kind of data in any Relational Database or NOSql will result in either joins or lookup to be performed while traversing.For this blog post we will be modelling data around Neo4j a Graph Database.
Neo4j Supports property graph – Graph with any number of vertices and edges each can have any number of properties (key / value pairs)

In our example we have Supplier with properties
Latitude
Longitude
TimeToSupplyProduct
SupplierID

and relationship Delivers with property
km

It’s natural to have suppliers across different geographic locations, represented by Latitude and Longitude in graph and connected to wholesalers by product that supplier is supplying.

For this blog post what important is the distance between supplier, product and wholesaler and then to retailer.
If we look in above diagram each supplier is connected to product they are supplying which are then connected to Wholesalers and Retailers by relationship Delivers with km as one of the property calculated using Haversine formula representing distance between their geographic locations.

Now we can easily traverse graph to calculate shortest path, time between different suppliers and retailers for different products.

If a Wholesaler wants to know the nearest supplier for a specific products, we need to start with that product find all suppliers supplying it and then sort by the distance between supplier and Wholeselar which is sum of
Distance b/w Supplier and product + Distance between Product and Wholeselar

Happy reading … ☺

Leave a Reply

Your email address will not be published.