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

Neo4j is AWESOME!

Neo4j is AWESOME!

Traditional relational databases — ironically — are not that good at the complex relationships some modern applications need.

Multiple joins and complex sub-queries can gradually take a toll on performance.

Graph Databases, on the other hand, are all about relationships. In this talk we will look at using the popular Neo4j graph database with PHP to build efficient relational data for OmNomHub: not your average recipe site.

Michelle Sanver

January 14, 2016
Tweet

More Decks by Michelle Sanver

Other Decks in Programming

Transcript

  1. (Michelle)-[:LOVES]->(Neo4j) @michellesanver Graphs \o/ A graph is an easy way

    to visualise connected data. Michelle Graphs likes
  2. (Michelle)-[:LOVES]->(Neo4j) @michellesanver Graphs vs. Relational databases Relational question: Average age

    of everyone in this list? Graph question: Who knows me from third parties?
  3. (Michelle)-[:LOVES]->(Neo4j) @michellesanver Graphs vs. Relational databases SET @entityid = '3';

    SELECT ea.attribute_id, ea.attribute_code, eav.value AS 'value', 'varchar' AS 'type' FROM catalog_category_entity e JOIN catalog_category_entity_varchar eav ON e.entity_id = eav.entity_id JOIN eav_attribute ea ON eav.attribute_id = ea.attribute_id WHERE e.entity_id = @entityid UNION SELECT ea.attribute_id, ea.attribute_code, eav.value AS 'value', 'int' AS 'type' FROM catalog_category_entity e JOIN catalog_category_entity_int eav ON e.entity_id = eav.entity_id JOIN eav_attribute ea ON eav.attribute_id = ea.attribute_id WHERE e.entity_id = @entityid UNION
  4. (Michelle)-[:LOVES]->(Neo4j) @michellesanver Graphs vs. Relational databases SELECT ea.attribute_id, ea.attribute_code, eav.value

    AS 'value', 'decimal' AS 'type' FROM catalog_category_entity e JOIN catalog_category_entity_decimal eav ON e.entity_id = eav.entity_id JOIN eav_attribute ea ON eav.attribute_id = ea.attribute_id WHERE e.entity_id = @entityid UNION selecting ea.attribute_id, ea.attribute_code, eav.value AS 'value', 'datetime' AS 'type' FROM catalog_category_entity e JOIN catalog_category_entity_datetime eav ON e.entity_id = eav.entity_id JOIN eav_attribute ea ON eav.attribute_id = ea.attribute_id WHERE e.entity_id = @entityid UNION SELECT ea.attribute_id, ea.attribute_code, eav.value AS 'value', 'text' AS 'type' FROM catalog_category_entity e JOIN catalog_category_entity_text eav ON e.entity_id = eav.entity_id JOIN eav_attribute ea ON eav.attribute_id = ea.attribute_id WHERE e.entity_id = @entityid
  5. (Michelle)-[:LOVES]->(Neo4j) @michellesanver Graphs and Neo4j (Node) { Properties } As

    many as you want Type: Person Nick: geekie Type: Person Nick: WyriHaximus
  6. (Michelle)-[:LOVES]->(Neo4j) @michellesanver Graphs and Neo4j (Node) [ Relationships ] As

    many as you want Type: Person Nick: geekie Type: Person Nick: WyriHaximus
  7. (Michelle)-[:LOVES]->(Neo4j) @michellesanver Neo4j architecture Disks File System Cache Record Files

    Object Cache Cypher Core API Traversal API Transaction Management Transaction Log
  8. (Michelle)-[:LOVES]->(Neo4j) @michellesanver Neo4j in PHP Neo4jPHP PHP Wrapper for the

    Neo4j graph database REST interface github.com/jadell/neo4jphp
  9. (Michelle)-[:LOVES]->(Neo4j) @michellesanver Neo4j in PHP Creating a node with the

    client $recipe = $client->makeNode(); $recipe->setProperty('title', ‘Spaghetti Bolognese') ->setProperty('Description', ‘Italian words') ->setProperty('Ingredients', ‘A lot') ->save(); $recipe->getId();
  10. (Michelle)-[:LOVES]->(Neo4j) @michellesanver Neo4j in PHP You get the idea, it’s

    well documented! Use $client to do anything, even Cypher queries. https://github.com/jadell/neo4jphp/wiki
  11. (Michelle)-[:LOVES]->(Neo4j) @michellesanver Neo4j in PHP In OmNomHub we’re using Symfony2

    There’s a bundle for that. https://github.com/klaussilveira/neo4j-client-bundle
  12. Resources (Michelle)-[:LOVES]->(Neo4j) @michellesanver docs.neo4j.org Graph Databases - Ian Robinson, 


    neo technology gives you the e-book version for free. neo4j.org/learn