Slide 1

Slide 1 text

( @michellesanver )-[:LOVES]->(Neo4j) Neo4J is AWESOME

Slide 2

Slide 2 text

( @michellesanver )-[:LOVES]->(Neo4j) WIIIIIIIE \o/ “Learn the most by sharing your knowledge with others” - @coderabbi

Slide 3

Slide 3 text

This talk is entry-level ( @michellesanver )-[:LOVES]->(Neo4j) It’s Open Source

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

( @michellesanver )-[:LOVES]->(Neo4j) Accent(s)!?

Slide 6

Slide 6 text

( @michellesanver )-[:LOVES]->(Neo4j)

Slide 7

Slide 7 text

( @michellesanver )-[:LOVES]->(Neo4j) I’m a data nerd Symfony is one of my main tools

Slide 8

Slide 8 text

( @michellesanver )-[:LOVES]->(Neo4j) YOU New to Graph DBs?

Slide 9

Slide 9 text

( @michellesanver )-[:LOVES]->(Neo4j) neo4j.com An open source graph database from Sweden

Slide 10

Slide 10 text

( @michellesanver )-[:LOVES]->(Neo4j) Community Edition

Slide 11

Slide 11 text

( @michellesanver )-[:LOVES]->(Neo4j) Enterprise Edition

Slide 12

Slide 12 text

( @michellesanver )-[:LOVES]->(Neo4j) Meetups everywhere neo4j.meetup.com

Slide 13

Slide 13 text

( @michellesanver )-[:LOVES]->(Neo4j) Graph theory has been studied since Leonard Euler’s Bridges 1736

Slide 14

Slide 14 text

( @michellesanver )-[:LOVES]->(Neo4j) Body Text

Slide 15

Slide 15 text

( @michellesanver )-[:LOVES]->(Neo4j)

Slide 16

Slide 16 text

( @michellesanver )-[:LOVES]->(Neo4j) Graphs is data, that is connected… They are everywhere

Slide 17

Slide 17 text

( @michellesanver )-[:LOVES]->(Neo4j) EVERYWHERE

Slide 18

Slide 18 text

( @michellesanver )-[:LOVES]->(Neo4j)

Slide 19

Slide 19 text

( @michellesanver )-[:LOVES]->(Neo4j) It’s modern.

Slide 20

Slide 20 text

( @michellesanver )-[:LOVES]->(Neo4j) Facebook Open Graph

Slide 21

Slide 21 text

( @michellesanver )-[:LOVES]->(Neo4j) Graphs \o/

Slide 22

Slide 22 text

( @michellesanver )-[:LOVES]->(Neo4j) A graph is an easy way to visualise connected data. Michelle Graphs likes

Slide 23

Slide 23 text

( @michellesanver )-[:LOVES]->(Neo4j) ( Nodes )

Slide 24

Slide 24 text

( @michellesanver )-[:LOVES]->(Neo4j) (Node) { Properties } As many as you want Name: Michelle Nick: geekie Name: Cees-Jan Nick: WyriHaximus

Slide 25

Slide 25 text

( @michellesanver )-[:LOVES]->(Neo4j) Nick: geekie Nick: WyriHaximus knows (Node) [ Relationships ] As many as you want

Slide 26

Slide 26 text

( @michellesanver )-[:LOVES]->(Neo4j) Labels: As many as you want Nick: geekie Label: Person

Slide 27

Slide 27 text

( @michellesanver )-[:LOVES]->(Neo4j) Indexes for easy lookup

Slide 28

Slide 28 text

( @michellesanver )-[:LOVES]->(Neo4j) Constraints

Slide 29

Slide 29 text

( @michellesanver )-[:LOVES]->(Neo4j) Constraints + Indexes = Optional schema

Slide 30

Slide 30 text

( @michellesanver )-[:LOVES]->(Neo4j) Local McLaughlin graph

Slide 31

Slide 31 text

( @michellesanver )-[:LOVES]->(Neo4j) Diamond Butterfly Bull Franklin Tutte Wagner

Slide 32

Slide 32 text

( @michellesanver )-[:LOVES]->(Neo4j) You can make art out of your DB. (Don’t, or do?)

Slide 33

Slide 33 text

( @michellesanver )-[:LOVES]->(Neo4j) Graphs vs. Relational

Slide 34

Slide 34 text

( @michellesanver )-[:LOVES]->(Neo4j) Relational question: Get me all recipes for this user Graph question: What recipe should we recommend the user to cook next?

Slide 35

Slide 35 text

( @michellesanver )-[:LOVES]->(Neo4j) Relational databases have tables Recipes

Slide 36

Slide 36 text

( @michellesanver )-[:LOVES]->(Neo4j) Tables have relationships Recipes Groups

Slide 37

Slide 37 text

( @michellesanver )-[:LOVES]->(Neo4j) Which causes a join table… Recipes Groups RecipeToGroup

Slide 38

Slide 38 text

( @michellesanver )-[:LOVES]->(Neo4j) You query via the table Recipes Groups RecipeToGroup

Slide 39

Slide 39 text

( @michellesanver )-[:LOVES]->(Neo4j) Imagine *actual* relationships Pasta (group) Spaghetti
 Bolognese
 (recipe) Italian (group) is_in is_in

Slide 40

Slide 40 text

( @michellesanver )-[:LOVES]->(Neo4j) Relational vs. Graph (1) Spaghetti Bolognese (2) Pasta (1) Italian Recipes Groups RecipeToGroup recipeId:1 | groupId: 1 recipeId:1 | groupId: 2 Pasta (group) Spaghetti
 Bolognese
 (recipe) Italian (group) is_in is_in

Slide 41

Slide 41 text

( @michellesanver )-[:LOVES]->(Neo4j) (1) Name: Pasta … Ingredients (1) Spaghetti Bolognese (2) Pasta (1) Italian Recipes Groups RecipeToGroup recipeId:1 | groupId: 1 recipeId:1 | groupId: 2 IngredientId: 1 RecipeId: 1 Unit: g Amount: 500 IngredientToRecipe (2) Name: Meat … IngredientId: 2 RecipeId: 1 Unit: g Amount: 800

Slide 42

Slide 42 text

( @michellesanver )-[:LOVES]->(Neo4j) Pasta (group) Italian (group) is_in is_in Italian (group) Meat (Ingredient) Pasta (Ingredient) contains amount: 500 unit: g contains
 amount: 800 unit: g Spaghetti
 Bolognese
 (recipe)

Slide 43

Slide 43 text

( @michellesanver )-[:LOVES]->(Neo4j) Joins in relational Performance degrades exponentially Corresponding in Neo4j Linear performance

Slide 44

Slide 44 text

( @michellesanver )-[:LOVES]->(Neo4j) Up to four million hops per second and core

Slide 45

Slide 45 text

( @michellesanver )-[:LOVES]->(Neo4j) Whiteboard Friendly

Slide 46

Slide 46 text

( @michellesanver )-[:LOVES]->(Neo4j) Relational databases have a structure

Slide 47

Slide 47 text

( @michellesanver )-[:LOVES]->(Neo4j) Neo4j has an optional structure

Slide 48

Slide 48 text

( @michellesanver )-[:LOVES]->(Neo4j) A big query. The EAV model.

Slide 49

Slide 49 text

( @michellesanver )-[:LOVES]->(Neo4j) 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

Slide 50

Slide 50 text

( @michellesanver )-[:LOVES]->(Neo4j) 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

Slide 51

Slide 51 text

( @michellesanver )-[:LOVES]->(Neo4j) Flexibility in a structured database is expensive.

Slide 52

Slide 52 text

Choose the right tool for the right job.

Slide 53

Slide 53 text

( @michellesanver )-[:LOVES]->(Neo4j) OmNomHub My pet project that is never done.

Slide 54

Slide 54 text

( @michellesanver )-[:LOVES]->(Neo4j) Fork A Recipe

Slide 55

Slide 55 text

( @michellesanver )-[:LOVES]->(Neo4j) Send change requests

Slide 56

Slide 56 text

( @michellesanver )-[:LOVES]->(Neo4j) Join groups and share recipe collections among them

Slide 57

Slide 57 text

( @michellesanver )-[:LOVES]->(Neo4j) Have your own private recipe collections

Slide 58

Slide 58 text

( @michellesanver )-[:LOVES]->(Neo4j) Search similar recipes (This is a part where the graph structure shines)

Slide 59

Slide 59 text

( @michellesanver )-[:LOVES]->(Neo4j) Neo4j architecture

Slide 60

Slide 60 text

( @michellesanver )-[:LOVES]->(Neo4j) Disks File System Cache Record Files Object Cache Cypher Core API Traversal API Transaction Management Transaction Log

Slide 61

Slide 61 text

( @michellesanver )-[:LOVES]->(Neo4j) Disks File System Cache Record Files Object Cache Cypher Core API Traversal API Transaction Management Transaction Log

Slide 62

Slide 62 text

( @michellesanver )-[:LOVES]->(Neo4j) Disks File System Cache Record Files Object Cache Cypher Core API Traversal API Transaction Management Transaction Log

Slide 63

Slide 63 text

( @michellesanver )-[:LOVES]->(Neo4j) Disks File System Cache Record Files Object Cache Cypher Core API Traversal API Transaction Management Transaction Log

Slide 64

Slide 64 text

( @michellesanver )-[:LOVES]->(Neo4j) Disks File System Cache Record Files Object Cache Cypher Core API Traversal API Transaction Management Transaction Log

Slide 65

Slide 65 text

( @michellesanver )-[:LOVES]->(Neo4j) Cypher Like SQL for graph databases.

Slide 66

Slide 66 text

( @michellesanver )-[:LOVES]->(Neo4j) ) Parentheses means nodes (Or hugs) (

Slide 67

Slide 67 text

( @michellesanver )-[:LOVES]->(Neo4j) } Curly braces means properties {

Slide 68

Slide 68 text

( @michellesanver )-[:LOVES]->(Neo4j) ] Square brackets means relationships [

Slide 69

Slide 69 text

( @michellesanver )-[:LOVES]->(Neo4j) Makes it easy to visualise and query the data. Browser

Slide 70

Slide 70 text

DEMO: Cypher and Browser ( @michellesanver )-[:LOVES]->(Neo4j)

Slide 71

Slide 71 text

( @michellesanver )-[:LOVES]->(Neo4j) Neo4j architecture Neostore File Storage

Slide 72

Slide 72 text

( @michellesanver )-[:LOVES]->(Neo4j) Neostore has several different store files

Slide 73

Slide 73 text

( @michellesanver )-[:LOVES]->(Neo4j) Each store has specific data

Slide 74

Slide 74 text

( @michellesanver )-[:LOVES]->(Neo4j) Nodes neostore.nodestore.db 9 bytes

Slide 75

Slide 75 text

( @michellesanver )-[:LOVES]->(Neo4j) Neostore Fixed size === FAST

Slide 76

Slide 76 text

( @michellesanver )-[:LOVES]->(Neo4j) Relationships neostore.relationshipstore.db 33 bytes

Slide 77

Slide 77 text

( @michellesanver )-[:LOVES]->(Neo4j) Properties neostore.propertystore.db neostore.propertystore.db.index neostore.propertystore.db.strings neostore.propertystore.db.arrays

Slide 78

Slide 78 text

( @michellesanver )-[:LOVES]->(Neo4j) Hardware matters!

Slide 79

Slide 79 text

( @michellesanver )-[:LOVES]->(Neo4j) Caching in memory, or filesystem

Slide 80

Slide 80 text

( @michellesanver )-[:LOVES]->(Neo4j) OmNomHub The future* * Maybe when my son moved away from home… In a land, far far away

Slide 81

Slide 81 text

( @michellesanver )-[:LOVES]->(Neo4j) Connecting users “You both like”

Slide 82

Slide 82 text

( @michellesanver )-[:LOVES]->(Neo4j) Connecting recipes “These have similar ingredients and user base”

Slide 83

Slide 83 text

( @michellesanver )-[:LOVES]->(Neo4j) Being smart “You might like”

Slide 84

Slide 84 text

( @michellesanver )-[:LOVES]->(Neo4j) Being smart Smart recipe collections!

Slide 85

Slide 85 text

( @michellesanver )-[:LOVES]->(Neo4j) Being creepy “Don’t like meat huh?”

Slide 86

Slide 86 text

( @michellesanver )-[:LOVES]->(Neo4j) Neo4j in PHP

Slide 87

Slide 87 text

( @michellesanver )-[:LOVES]->(Neo4j) As we saw There’s a REST interface!

Slide 88

Slide 88 text

( @michellesanver )-[:LOVES]->(Neo4j) GraphAware PHP Client https://github.com/graphaware/neo4j-php-client

Slide 89

Slide 89 text

( @michellesanver )-[:LOVES]->(Neo4j) $client = ClientBuilder::create()
 ->addConnection('bolt', 'bolt://neo4j:password@localhost:7687')
 ->build(); 
 $query = "MATCH (n:User) RETURN n.name”;
 $result = $client->run($query);
 
 foreach ($result->getRecords() as $record) {
 echo(count($record->value('name'));
 }


Slide 90

Slide 90 text

( @michellesanver )-[:LOVES]->(Neo4j) $client = ClientBuilder::create()
 ->addConnection('bolt', 'bolt://neo4j:password@localhost:7687')
 ->build(); 
 $query = "MATCH (n:User) RETURN n.name”;
 $result = $client->run($query);
 
 foreach ($result->getRecords() as $record) {
 echo(count($record->value('name'));
 }


Slide 91

Slide 91 text

( @michellesanver )-[:LOVES]->(Neo4j) $client = ClientBuilder::create()
 ->addConnection('bolt', 'bolt://neo4j:password@localhost:7687')
 ->build(); 
 $query = "MATCH (n:User) RETURN n.name”;
 $result = $client->run($query);
 
 foreach ($result->getRecords() as $record) {
 echo(count($record->value('name'));
 }


Slide 92

Slide 92 text

( @michellesanver )-[:LOVES]->(Neo4j) $client = ClientBuilder::create()
 ->addConnection('bolt', 'bolt://neo4j:password@localhost:7687')
 ->build(); 
 $query = "MATCH (n:User) RETURN n.name”;
 $result = $client->run($query);
 
 foreach ($result->getRecords() as $record) {
 echo(count($record->get('name'));
 }


Slide 93

Slide 93 text

( @michellesanver )-[:LOVES]->(Neo4j) GraphAware also released an OGM

Slide 94

Slide 94 text

( @michellesanver )-[:LOVES]->(Neo4j) /**
 * @OGM\GraphId()
 * @var int
 */
 protected $id;
 
 /**
 * @OGM\Property(type="string")
 * @var string
 */
 protected $recipeName;
 
 /**
 * @OGM\Relationship(type="FORKED", direction="OUTGOING", targetEntity="User", collection=true)
 * @var ArrayCollection|User[]
 */
 protected $users;

Slide 95

Slide 95 text

( @michellesanver )-[:LOVES]->(Neo4j) /**
 * @OGM\GraphId()
 * @var int
 */
 protected $id;
 
 /**
 * @OGM\Property(type="string")
 * @var string
 */
 protected $recipeName;
 
 /**
 * @OGM\Relationship(type="FORKED", direction="OUTGOING", targetEntity="User", collection=true)
 * @var ArrayCollection|User[]
 */
 protected $users;

Slide 96

Slide 96 text

( @michellesanver )-[:LOVES]->(Neo4j) /**
 * @OGM\GraphId()
 * @var int
 */
 protected $id;
 
 /**
 * @OGM\Property(type="string")
 * @var string
 */
 protected $recipeName;
 
 /**
 * @OGM\Relationship(type="FORKED", direction="OUTGOING", targetEntity="User", collection=true)
 * @var ArrayCollection|User[]
 */
 protected $users;

Slide 97

Slide 97 text

( @michellesanver )-[:LOVES]->(Neo4j) /**
 * @OGM\GraphId()
 * @var int
 */
 protected $id;
 
 /**
 * @OGM\Property(type="string")
 * @var string
 */
 protected $recipeName;
 
 /**
 * @OGM\Relationship(type="FORKED", direction="OUTGOING", targetEntity="User", collection=true)
 * @var ArrayCollection|User[]
 */
 protected $users;

Slide 98

Slide 98 text

( @michellesanver )-[:LOVES]->(Neo4j) $user = $em->getRepository(User::class) ->findOneBy(‘name’, 'Michelle');

Slide 99

Slide 99 text

( @michellesanver )-[:LOVES]->(Neo4j) Neo4j + PHP is well documented https://neo4j.com/developer/php/ https://github.com/graphaware/neo4j-php-client https://github.com/graphaware/neo4j-php-ogm

Slide 100

Slide 100 text

( @michellesanver )-[:LOVES]->(Neo4j) Wrapup

Slide 101

Slide 101 text

( @michellesanver )-[:LOVES]->(Neo4j) Graphs are everywhere

Slide 102

Slide 102 text

( @michellesanver )-[:LOVES]->(Neo4j) Graphs make it easier to visualise complex data

Slide 103

Slide 103 text

( @michellesanver )-[:LOVES]->(Neo4j) Graphs make it easier to… Be creepily smart <3

Slide 104

Slide 104 text

( @michellesanver )-[:LOVES]->(Neo4j) Resources neo4j.org/learn neo4j.com/developer/php github.com/neo4j-contrib/neo4j-symfony

Slide 105

Slide 105 text

( @michellesanver )-[:LOVES]->(Neo4j) Thank you Questions?

Slide 106

Slide 106 text

( @michellesanver )-[:LOVES]->(Neo4j) YOU are AWESOME Thank you

Slide 107

Slide 107 text

( @michellesanver )-[:LOVES]->(Neo4j) Graph databases How would you use them?