Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

Vranac Srdjan

August 05, 2015

More Decks by Vranac Srdjan

Other Decks in Programming


  1. 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
  2. Databases are great, Databases are fun, Databases make our connected

    world run — Vranac Code4Hire, 2015, DaFed 3
  3. 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
  4. Neo4j Use Cases: • matchmaking • network management • software

    analytics • scientific research • routing Code4Hire, 2015, DaFed 15
  5. 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
  6. Nodes, Relationships, Labels, oh my... CREATE (c:Cake { type: 'Chocolate'

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

    }), (b:Dessert { season: 'Any' }) CREATE (a)-[:IS_TYPE_OF]->(b) Code4Hire, 2015, DaFed 19
  8. Find all Products SQL: SELECT p.* FROM products as p;

    Cypher: MATCH (p:Product) RETURN p; Code4Hire, 2015, DaFed 22
  9. 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
  10. 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
  11. 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
  12. Is that a date or you are just timestamping? 08/03/2015

    @ 2:20pm (UTC) -> 1438611609 Code4Hire, 2015, DaFed 30
  13. 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