no sql
play

No SQL? Image credit: http://browsertoolkit.com/fault-tolerance.png - PowerPoint PPT Presentation

No SQL? Image credit: http://browsertoolkit.com/fault-tolerance.png Neo4j the benefits of graph databases #neo4j Emil Eifrem @emileifrem emil@neotechnology.com CEO, Neo Technology Death? Community experimentation: CouchDB Redis


  1. No SQL? Image credit: http://browsertoolkit.com/fault-tolerance.png

  2. Neo4j the benefits of graph databases #neo4j Emil Eifrem @emileifrem emil@neotechnology.com CEO, Neo Technology

  3. Death? Community experimentation: CouchDB Redis Hypertable Cassandra Scalaris ...

  4. ?

  5. Trend 1: data is getting more connected Giant Global Information connectivity Graph (GGG) Ontologies RDF Folksonomies Tagging User- Wikis generated content Blogs RSS Hypertext Text web 1.0 web 2.0 “web 3.0” documents 1990 2000 2010 2020

  6. Trend 2: ... and more semi-structured Individualization of content! In the salary lists of the 1970s, all elements had exactly one job In the salary lists of the 2000s, we need 5 job columns! Or 8? Or 15? Trend accelerated by the decentralization of content generation that is the hallmark of the age of participation (“web 2.0”)

  7. Relational database Salary List Performance Majority of Webapps Social network Semantic } Trading custom Information complexity

  8. We = hackers! So that’s v CPU ... what about v hackers ?

  9. Whiteboard friendly? ? owns Björn Björn Big Car build transport , Kids & DayCare Veggies

  10. Alternative? a graph database

  11. The Graph DB model: representation Core abstractions: name = “Emil” age = 29 Nodes sex = “yes” Relationships between nodes 1 2 1 2 Properties on both type = KNOWS 3 3 time = 4 years type = car vendor = “SAAB” model = “95 Aero”

  12. Example: The Matrix name = “The Architect” name = “Morpheus” rank = “Captain” 42 42 occupation = “Total badass” name = “Thomas Anderson” age = 29 disclosure = public KNOWS KNOWS CODED_BY 1 K 1 7 7 3 3 N O W S 13 13 S K W name = “Cypher” N O O W last name = “Reagan” S N K name = “Agent Smith” version = 1.0b disclosure = secret age = 3 days language = C++ age = 6 months 2 2 name = “Trinity”

  13. Code (1): Building a node space NeoService neo = ... // Get factory // Create Thomas 'Neo' Anderson Node mrAnderson = neo.createNode(); mrAnderson.setProperty( "name", "Thomas Anderson" ); mrAnderson.setProperty( "age", 29 ); // Create Morpheus Node morpheus = neo.createNode(); morpheus.setProperty( "name", "Morpheus" ); morpheus.setProperty( "rank", "Captain" ); morpheus.setProperty( "occupation", "Total bad ass" ); // Create a relationship representing that they know each other mrAnderson.createRelationshipTo( morpheus, RelTypes. KNOWS ); // ...create Trinity, Cypher, Agent Smith, Architect similarly

  14. Code (1): Building a node space NeoService neo = ... // Get factory Transaction tx = neo.beginTx(); // Create Thomas 'Neo' Anderson Node mrAnderson = neo.createNode(); mrAnderson.setProperty( "name", "Thomas Anderson" ); mrAnderson.setProperty( "age", 29 ); // Create Morpheus Node morpheus = neo.createNode(); morpheus.setProperty( "name", "Morpheus" ); morpheus.setProperty( "rank", "Captain" ); morpheus.setProperty( "occupation", "Total bad ass" ); // Create a relationship representing that they know each other mrAnderson.createRelationshipTo( morpheus, RelTypes. KNOWS ); // ...create Trinity, Cypher, Agent Smith, Architect similarly tx.commit();

  15. Code (1b): Defining RelationshipTypes // In package org.neo4j.api.core public interface RelationshipType { String name() ; } // In package org.yourdomain.yourapp // Example on how to roll dynamic RelationshipTypes class MyDynamicRelType implements RelationshipType { private final String name ; MyDynamicRelType ( String name ){ this. name = name ; } public String name() { return this .name; } } // Example on how to kick it, static-RelationshipType-like enum MyStaticRelTypes implements RelationshipType { KNOWS, WORKS_FOR, }

  16. The Graph DB model: traversal Traverser framework for name = “Emil” high-performance traversing age = 29 sex = “yes” across the node space 1 2 1 2 type = KNOWS 3 3 time = 4 years type = car vendor = “SAAB” model = “95 Aero”

  17. Example: Mr Anderson’s friends name = “The Architect” name = “Morpheus” rank = “Captain” 42 42 occupation = “Total badass” name = “Thomas Anderson” age = 29 disclosure = public KNOWS KNOWS CODED_BY 1 K 1 7 7 3 3 N O W S 13 13 S K W name = “Cypher” N O O W last name = “Reagan” S N K name = “Agent Smith” version = 1.0b disclosure = secret age = 3 days language = C++ age = 6 months 2 2 name = “Trinity”

  18. Code (2): Traversing a node space // Instantiate a traverser that returns Mr Anderson's friends Traverser friendsTraverser = mrAnderson.traverse( Traverser.Order.BREADTH_FIRST, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL_BUT_START_NODE, RelTypes.KNOWS, Direction.OUTGOING ); // Traverse the node space and print out the result System.out.println( "Mr Anderson's friends:" ); for ( Node friend : friendsTraverser ) { System.out.printf( "At depth %d => %s%n", friendsTraverser.currentPosition().getDepth(), friend.getProperty( "name" ) ); }

  19. name = “The Architect” name = “Morpheus” rank = “Captain” 42 42 occupation = “Total badass” name = “Thomas Anderson” age = 29 disclosure = public KNOWS KNOWS CODED_BY K 1 1 7 3 7 3 N O W S 13 13 S K W name = “Cypher” N O O W last name = “Reagan” S N K name = “Agent Smith” version = 1.0b disclosure = secret age = 3 days language = C++ age = 6 months 2 2 $ bin/start-neo-example name = “Trinity” Mr Anderson's friends: At depth 1 => Morpheus friendsTraverser = mrAnderson.traverse( At depth 1 => Trinity Traverser.Order. BREADTH_FIRST , At depth 2 => Cypher StopEvaluator. END_OF_GRAPH , ReturnableEvaluator. ALL_BUT_START_NODE , At depth 3 => Agent Smith RelTypes. KNOWS , $ Direction. OUTGOING );

  20. Example: Friends in love? name = “The Architect” name = “Morpheus” rank = “Captain” 42 42 occupation = “Total badass” name = “Thomas Anderson” age = 29 disclosure = public KNOWS KNOWS CODED_BY 1 1 7 3 K 7 3 N O W S 13 13 S K W name = “Cypher” N O O W last name = “Reagan” S N K name = “Agent Smith” version = 1.0b L disclosure = secret O V language = C++ age = 6 months E S 2 2 name = “Trinity”

  21. Code (3a): Custom traverser // Create a traverser that returns all “friends in love” Traverser loveTraverser = mrAnderson.traverse( Traverser.Order.BREADTH_FIRST, StopEvaluator.END_OF_GRAPH, new ReturnableEvaluator() { public boolean isReturnableNode( TraversalPosition pos ) { return pos.currentNode().hasRelationship( RelTypes.LOVES, Direction.OUTGOING ); } }, RelTypes.KNOWS, Direction.OUTGOING );

  22. Code (3a): Custom traverser // Traverse the node space and print out the result System.out.println( "Who’s a lover?" ); for ( Node person : loveTraverser ) { System.out.printf( "At depth %d => %s%n", loveTraverser.currentPosition().getDepth(), person.getProperty( "name" ) ); }

  23. name = “The Architect” name = “Morpheus” rank = “Captain” 42 42 occupation = “Total badass” name = “Thomas Anderson” age = 29 disclosure = public KNOWS KNOWS CODED_BY KNOWS 1 1 7 3 7 3 13 13 S K W name = “Cypher” N O O W last name = “Reagan” S N K name = “Agent Smith” version = 1.0b disclosure = secret L O V language = C++ age = 6 months E 2 S 2 name = “Trinity” $ bin/start-neo-example Who’s a lover? new ReturnableEvaluator() { At depth 1 => Trinity public boolean isReturnableNode( TraversalPosition pos) $ { return pos.currentNode(). hasRelationship( RelTypes. LOVES, Direction .OUTGOING ); } },

  24. Bonus code: domain model How do you implement your domain model? Use the delegator pattern, i.e. every domain entity wraps a Neo4j primitive: // In package org.yourdomain.yourapp class PersonImpl implements Person { private final Node underlyingNode ; PersonImpl ( Node node ){ this. underlyingNode = node ; } public String getName () { return this .underlyingNode.getProperty( "name" ); } public void setName ( String name ) { this .underlyingNode.setProperty( "name" , name ); } }

  25. Domain layer frameworks Qi4j (www.qi4j.org) Framework for doing DDD in pure Java5 Defines Entities / Associations / Properties Sound familiar? Nodes / Rel’s / Properties! Neo4j is an “EntityStore” backend NeoWeaver ( http://components.neo4j.org/neo-weaver ) Weaves Neo4j-backed persistence into domain objects in runtime (dynamic proxy / cglib based) Veeeery alpha

  26. Neo4j system characteristics Disk-based Native graph storage engine with custom (“SSD- ready”) binary on-disk format Transactional JTA/JTS, XA, 2PC, Tx recovery, deadlock detection, etc Scalable Several billions of nodes/rels/props on single JVM Robust 6+ years in 24/7 production

  27. Social network pathExists() 12 12 ~1k persons 3 Avg 50 friends per 3 1 1 7 7 person pathExists(a, b) limit 36 depth 4 36 41 77 41 77 5 5 Two backends Eliminate disk IO so warm up caches

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend