Neo4j - Connecting the dots

Neo4j - Connecting the dots

Relation Databases have been around for a very long time. They are rock solid, they offer you a lot of power and flexibility, but often at the price of performance.
What do you do if you have highly connected data, that you need to query, and it has multiple joins and subqueries, and of course you need the results ASAP so long running queries are out of the question?
Well, maybe it is time to look at a graph DB called Neo4j and what it can do for you.
In this talk we will go over the features, possibilities, highs and the lows of Neo4j.

F2d82b268a7cbccc9809c939428df64f?s=128

Vranac Srdjan

August 05, 2015
Tweet

Transcript

  1. Neo4j connecting the dots Code4Hire, 2015, DaFed 1

  2. business owner, developer, consultant, mercenary, writing terrible code that performs

    exceptionally, wrangling elePHPants and Pythons, obsessed with process automation, interested in continuous integration and delivery, clean code, testing, best practices and distributed systems Code4Hire, 2015, DaFed 2
  3. Databases are great, Databases are fun, Databases make our connected

    world run — Vranac Code4Hire, 2015, DaFed 3
  4. Special cases and snowflakes • Storing structured product information? Store

    as a document. • Describing how a user got from point A to point B? Follow a graph. Code4Hire, 2015, DaFed 4
  5. NoSQL Code4Hire, 2015, DaFed 5

  6. <rant> Code4Hire, 2015, DaFed 6

  7. Nazgûl Code4Hire, 2015, DaFed 7

  8. Code4Hire, 2015, DaFed 8

  9. NO! Squeal! Code4Hire, 2015, DaFed 9

  10. </rant> Code4Hire, 2015, DaFed 10

  11. Graph? Code4Hire, 2015, DaFed 11

  12. 7 Bridges of koenigsburg Code4Hire, 2015, DaFed 12

  13. From Designer To Developer Code4Hire, 2015, DaFed 13

  14. Graph Database Code4Hire, 2015, DaFed 14

  15. Neo4j Use Cases: • matchmaking • network management • software

    analytics • scientific research • routing Code4Hire, 2015, DaFed 15
  16. hhhhhhh h:::::h h:::::h h:::::h ccccccccccccccccyyyyyyy yyyyyyyppppp ppppppppp h::::h hhhhh eeeeeeeeeeee

    rrrrr rrrrrrrrr cc:::::::::::::::c y:::::y y:::::y p::::ppp:::::::::p h::::hh:::::hhh ee::::::::::::ee r::::rrr:::::::::r c:::::::::::::::::c y:::::y y:::::y p:::::::::::::::::p h::::::::::::::hh e::::::eeeee:::::eer:::::::::::::::::r c:::::::cccccc:::::c y:::::y y:::::y pp::::::ppppp::::::ph:::::::hhh::::::h e::::::e e:::::err::::::rrrrr::::::r c::::::c ccccccc y:::::y y:::::y p:::::p p:::::ph::::::h h::::::he:::::::eeeee::::::e r:::::r r:::::r c:::::c y:::::y y:::::y p:::::p p:::::ph:::::h h:::::he:::::::::::::::::e r:::::r rrrrrrr c:::::c y:::::y:::::y p:::::p p:::::ph:::::h h:::::he::::::eeeeeeeeeee r:::::r c::::::c ccccccc y:::::::::y p:::::p p::::::ph:::::h h:::::he:::::::e r:::::r c:::::::cccccc:::::c y:::::::y p:::::ppppp:::::::ph:::::h h:::::he::::::::e r:::::r c:::::::::::::::::c y:::::y p::::::::::::::::p h:::::h h:::::h e::::::::eeeeeeee r:::::r cc:::::::::::::::c y:::::y p::::::::::::::pp h:::::h h:::::h ee:::::::::::::e r:::::r cccccccccccccccc y:::::y p::::::pppppppp hhhhhhh hhhhhhh eeeeeeeeeeeeee rrrrrrr y:::::y p:::::p y:::::y p:::::p y:::::y p:::::::p y:::::y p:::::::p yyyyyyy p:::::::p ppppppppp Code4Hire, 2015, DaFed 16
  17. Nodes, Relationships, Labels, oh my... Code4Hire, 2015, DaFed 17

  18. Nodes, Relationships, Labels, oh my... CREATE (c:Cake { type: 'Chocolate'

    }) RETURN c CREATE (d:Dessert { season: 'Any' }) RETURN d Code4Hire, 2015, DaFed 18
  19. Nodes, Relationships, Labels, oh my... MATCH (a:Cake { type: 'Chocolate'

    }), (b:Dessert { season: 'Any' }) CREATE (a)-[:IS_TYPE_OF]->(b) Code4Hire, 2015, DaFed 19
  20. Voilà Code4Hire, 2015, DaFed 20

  21. Comparative Examples Code4Hire, 2015, DaFed 21

  22. Find all Products SQL: SELECT p.* FROM products as p;

    Cypher: MATCH (p:Product) RETURN p; Code4Hire, 2015, DaFed 22
  23. Field Access, Ordering and Paging SQL: SELECT p.ProductName, p.UnitPrice FROM

    products as p ORDER BY p.UnitPrice DESC LIMIT 10; Cypher: MATCH (p:Product) RETURN p.productName, p.unitPrice ORDER BY p.unitPrice DESC LIMIT 10; Code4Hire, 2015, DaFed 23
  24. Joining Products with Customers SQL: SELECT distinct c.CompanyName FROM customers

    AS c JOIN orders AS o ON (c.CustomerID = o.CustomerID) JOIN order_details AS od ON (o.OrderID = od.OrderID) JOIN products as p ON (od.ProductID = p.ProductID) WHERE p.ProductName = 'Chocolade'; Code4Hire, 2015, DaFed 24
  25. Joining Products with Customers Cypher: MATCH (p:Product {productName:"Chocolade"})<-[:PRODUCT]- (:Order)<-[:PURCHASED]-(c:Customer) RETURN

    distinct c.companyName; Code4Hire, 2015, DaFed 25
  26. Hierarchies and Trees, Variable Length Joins SQL: SELECT p.ProductName FROM

    Product as p JOIN ProductCategory pc ON (p.CategoryID = pc.CategoryID AND pc.CategoryName = "Dairy Products") JOIN ProductCategory pc1 ON (p.CategoryID = pc1.CategoryID JOIN ProductCategory pc2 ON (pc2.ParentID = pc2.CategoryID AND pc2.CategoryName = "Dairy Products") JOIN ProductCategory pc3 ON (p.CategoryID = pc3.CategoryID JOIN ProductCategory pc4 ON (pc3.ParentID = pc4.CategoryID) JOIN ProductCategory pc5 ON (pc4.ParentID = pc5.CategoryID AND pc5.CategoryName = "Dairy Products") ; Code4Hire, 2015, DaFed 26
  27. Hierarchies and Trees, Variable Length Joins Cypher: MATCH (p:Product)-[:CATEGORY]->(l:ProductCategory)-[:PARENT*0..]- (:ProductCategory

    {name:"Dairy Products"}) RETURN p.name Code4Hire, 2015, DaFed 27
  28. Demo Time Code4Hire, 2015, DaFed 28

  29. The bad & The Ugly Code4Hire, 2015, DaFed 29

  30. Is that a date or you are just timestamping? 08/03/2015

    @ 2:20pm (UTC) -> 1438611609 Code4Hire, 2015, DaFed 30
  31. Import Data CREATE CONSTRAINT ON (deal:Deal) ASSERT deal.id IS UNIQUE;

    USING PERIODIC COMMIT 5000 LOAD CSV WITH HEADERS FROM "file:///Users/vranac/dev/deals/temp/deals_100k.csv" AS row WITH row MERGE (d:Deal {Id: row.id}) ON CREATE SET d.Id = row.id, d.a = row.a, d.b = row.b, ON MATCH SET d.a = row.a, d.b = row.b, ; Code4Hire, 2015, DaFed 31
  32. Long queries timeout Code4Hire, 2015, DaFed 32

  33. The End Thank You! Questions? Code4Hire, 2015, DaFed 33