SlideShare a Scribd company logo
1 of 18
By András Fehér
THE REAL VALUE IS IN THE RELATIONSHIPS
• Google : Knowledge Graph
• Facebook: Unicorn
• Twitter: flockdb
• ....
WHAT IS THE PROBLEM WITH RDBMS? (PART 1)
The base question of all recommendation systems:
“User 99 has bought the products 1, 2, 3 and 765 so far. Get the list of other products bought by other users together
with the products 1, 2, 3 or 765 in descending order by popularity”
WHAT IS THE PROBLEM WITH RDBMS? (PART 2)
“Who are Bob’s friends-of-friends-of-friends?”
“What is the shortest path between two specific friends?”
...?
BASICS: WHAT IS A GRAPH?
• Origin: Euler 18th century
• It contains nodes and relationships.
• Nodes contain properties (key-value pairs).
• Nodes can be labeled with one or more labels.
• Relationships are named and directed, and
always have a start and end node.
• Relationships can also contain properties.
GRAPH DATABASES ON THE MARKET
• Non-native storage: data in
general purpose DB
• Native processing: index-free
SOCIAL NETWORK SPEED TEST
1 000 000 people each with approximately 50 friends:
USE CASES *
• Fraud Detection
• Graph-Based Search
• Identity and Access Management
• Master Data Management
• Network and IT Operations
• Real-Time Recommendations
• Social Network
* Detailed examples from Neo4j
DATA MODELING
• concept -> logical model -> physical model
• big gap between concept and DB
• structure and data volume determines query speed
• hard to change schema
• concept directly to DB
• no gap between concept and DB
• query speed not influenced by structure or data
volume
• easy to change connections
CYPHER – GRAPH DATABASE QUERY LANGUAGE
Name:
Joe
Name:
Bob
FRIEND
Person Person
(:Person{name:”Joe”})-[:FRIEND]->(:Person{name:”Bob”})
• Other query languages: SPARQL, Gremlin ...
• Case sensitive
• Most human friendly
CREATING SOME TEST DATA IN CYPHER
// creating nodes
create(:Person{name:"Tom Hanks"});
....
// creating relation between two specific nodes
match (a:Person),(b:Movie)
where
a.name='Ron Howard'
and b.title = 'The Da Vinci Code'
create (a)-[r:DIRECTED]->(b) return r;
....
// set relation property
match(Person{name:"Tom Hanks"})-[n:KNOWS]->
(Person{name:„Ron Howard"}) set n.since=1987;
....
// delete relation
match (a)-[r:KNOWS]->(b)
where
a.name='Matt Damon'
and b.name='Matt Damon'
delete r;
QUERYING DATA IN CYPHER
// whom does Tom Hanks know?
match (:Person{name:"Tom Hanks"})-[r:KNOWS]->(b) return b;
// who knows Steven Spielberg?
match (:Person{name:"Steven Spielberg"})<-[:KNOWS]-(b) return b;
// which films has Tom Hanks Acted in?
match (:Person{name:"Tom Hanks"})-[:ACTED_IN]-(b) return b;
// delete by id
match (n) where ID(n)=11 delete n;
// get Steven Spielberg aquantances 3 levels deep
match (:Person{name:"Steven Spielberg"})
-[:KNOWS]-(b)
-[:KNOWS]-(c)
-[:KNOWS]-(d)
return b, c, d
A BIGGER EXAMPLE
MATCH (tom:Person {name:"Tom Hanks"})
-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors)
RETURN tom, m, coActors
Tom Hanks’ co-actors:
FINDING THE SHORTEST PATH
MATCH p=shortestPath(
(kevin:Person {name:"Kevin Bacon"})-[*]-(meg:Person {name:"Meg Ryan"})
)
RETURN p
The shortest path between Kevin Bacon and Meg Ryan:
RECOMMENDING CO-ACTORS TO TOM HANKS
MATCH
// coActors: acted in the same movies as Tom
// cocoActors: acted in the same movies as coActors but they Tom did not
// act in the same movies as the coActors
(tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors),
(coActors)-[:ACTED_IN]->(m2)<-[:ACTED_IN]-(cocoActors)
WHERE NOT (tom)-[:ACTED_IN]->(m2)
RETURN
cocoActors.name AS Recommended,
// strength: how many times the same cocoActor was found
count(*) AS Strength ORDER BY Strength DESC
Find co-actors who haven't work with Tom Hanks (co-co-actors):
Tom
m
(movie)
ACTED_IN
coActor
ACTED_IN
m2
(movie)
ACTED_IN
cocoActor
ACTED_IN
ACTED_IN
NEO4J CLUSTER ARCHITECTURE
• Automatic master election
• Possible to write to slaves, but it is faster to the master
• Full replication (/data redundancy); graph sharding is under development
• Single server capacity: 34 billion nodes, 34 billion relationships, 65 thousands relationship types
and 68 billion properties
• Cluster requires a quorum in order to serve write load
• Reads done on slaves : reads scale linearly
• Exceptionally high write loads: queing and vertical scaling
• Large graph that does not fit in RAM: cache sharding by routing queries
• Online backups full / incremental supported
• Reporting instances are slaves that will never be elected to be master
DEVELOPMENT
Query tuning:
• execution plan
• profiling
Indexing on properties
Accessing:
• web interface
• REST API
• shell
• embedding in Java applications
• Mazerunner extension (Using Apache Spark and Neo4j for Big Data Graph Analytics)
Utilities
• neo4j-shell
• neo4j-import
• neo4j-backup
• neo4j-arbiter
RESOURCES
Good official manual
From Relational to Graph:
A Developer's Guide

More Related Content

Similar to Neo4j 20 minutes introduction

Introduction to neo4j - a hands-on crash course
Introduction to neo4j - a hands-on crash courseIntroduction to neo4j - a hands-on crash course
Introduction to neo4j - a hands-on crash courseNeo4j
 
SDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and modelsSDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and modelsKorea Sdec
 
GraphTour Boston - Graphs for AI and ML
GraphTour Boston - Graphs for AI and MLGraphTour Boston - Graphs for AI and ML
GraphTour Boston - Graphs for AI and MLNeo4j
 
Bootstrapping Recommendations with Neo4j
Bootstrapping Recommendations with Neo4jBootstrapping Recommendations with Neo4j
Bootstrapping Recommendations with Neo4jMax De Marzi
 
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH) Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH) David Fombella Pombal
 
Introduction to graph databases in term of neo4j
Introduction to graph databases in term of neo4jIntroduction to graph databases in term of neo4j
Introduction to graph databases in term of neo4jAbdullah Hamidi
 
Neo4j graphdatabaseforrecommendations-130531021030-phpapp02-converted
Neo4j graphdatabaseforrecommendations-130531021030-phpapp02-convertedNeo4j graphdatabaseforrecommendations-130531021030-phpapp02-converted
Neo4j graphdatabaseforrecommendations-130531021030-phpapp02-convertedsnehapandey01
 
MongoSV Schema Workshop
MongoSV Schema WorkshopMongoSV Schema Workshop
MongoSV Schema WorkshopMongoDB
 
Modeling JSON data for NoSQL document databases
Modeling JSON data for NoSQL document databasesModeling JSON data for NoSQL document databases
Modeling JSON data for NoSQL document databasesRyan CrawCour
 
Neo4j - graph database for recommendations
Neo4j - graph database for recommendationsNeo4j - graph database for recommendations
Neo4j - graph database for recommendationsproksik
 
Introduction to Neo4j and .Net
Introduction to Neo4j and .NetIntroduction to Neo4j and .Net
Introduction to Neo4j and .NetNeo4j
 
Choosing the right NOSQL database
Choosing the right NOSQL databaseChoosing the right NOSQL database
Choosing the right NOSQL databaseTobias Lindaaker
 
Webinar: Schema Design
Webinar: Schema DesignWebinar: Schema Design
Webinar: Schema DesignMongoDB
 
A Little Graph Theory for the Busy Developer - Jim Webber @ GraphConnect Chic...
A Little Graph Theory for the Busy Developer - Jim Webber @ GraphConnect Chic...A Little Graph Theory for the Busy Developer - Jim Webber @ GraphConnect Chic...
A Little Graph Theory for the Busy Developer - Jim Webber @ GraphConnect Chic...Neo4j
 
Graph Databases
Graph DatabasesGraph Databases
Graph Databasesthai
 
(BDT203) From Zero to NoSQL Hero: Amazon DynamoDB Tutorial | AWS re:Invent 2014
(BDT203) From Zero to NoSQL Hero: Amazon DynamoDB Tutorial | AWS re:Invent 2014(BDT203) From Zero to NoSQL Hero: Amazon DynamoDB Tutorial | AWS re:Invent 2014
(BDT203) From Zero to NoSQL Hero: Amazon DynamoDB Tutorial | AWS re:Invent 2014Amazon Web Services
 

Similar to Neo4j 20 minutes introduction (20)

Introduction to neo4j - a hands-on crash course
Introduction to neo4j - a hands-on crash courseIntroduction to neo4j - a hands-on crash course
Introduction to neo4j - a hands-on crash course
 
MongoDB
MongoDBMongoDB
MongoDB
 
Couchdb Nosql
Couchdb NosqlCouchdb Nosql
Couchdb Nosql
 
SDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and modelsSDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and models
 
GraphTour Boston - Graphs for AI and ML
GraphTour Boston - Graphs for AI and MLGraphTour Boston - Graphs for AI and ML
GraphTour Boston - Graphs for AI and ML
 
Bootstrapping Recommendations with Neo4j
Bootstrapping Recommendations with Neo4jBootstrapping Recommendations with Neo4j
Bootstrapping Recommendations with Neo4j
 
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH) Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
 
Introduction to graph databases in term of neo4j
Introduction to graph databases in term of neo4jIntroduction to graph databases in term of neo4j
Introduction to graph databases in term of neo4j
 
NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
 
Neo4j graphdatabaseforrecommendations-130531021030-phpapp02-converted
Neo4j graphdatabaseforrecommendations-130531021030-phpapp02-convertedNeo4j graphdatabaseforrecommendations-130531021030-phpapp02-converted
Neo4j graphdatabaseforrecommendations-130531021030-phpapp02-converted
 
MongoSV Schema Workshop
MongoSV Schema WorkshopMongoSV Schema Workshop
MongoSV Schema Workshop
 
Modeling JSON data for NoSQL document databases
Modeling JSON data for NoSQL document databasesModeling JSON data for NoSQL document databases
Modeling JSON data for NoSQL document databases
 
Neo4j - graph database for recommendations
Neo4j - graph database for recommendationsNeo4j - graph database for recommendations
Neo4j - graph database for recommendations
 
Introduction to Neo4j and .Net
Introduction to Neo4j and .NetIntroduction to Neo4j and .Net
Introduction to Neo4j and .Net
 
Choosing the right NOSQL database
Choosing the right NOSQL databaseChoosing the right NOSQL database
Choosing the right NOSQL database
 
Webinar: Schema Design
Webinar: Schema DesignWebinar: Schema Design
Webinar: Schema Design
 
A Little Graph Theory for the Busy Developer - Jim Webber @ GraphConnect Chic...
A Little Graph Theory for the Busy Developer - Jim Webber @ GraphConnect Chic...A Little Graph Theory for the Busy Developer - Jim Webber @ GraphConnect Chic...
A Little Graph Theory for the Busy Developer - Jim Webber @ GraphConnect Chic...
 
Graph Databases
Graph DatabasesGraph Databases
Graph Databases
 
Database History From Codd to Brewer
Database History From Codd to BrewerDatabase History From Codd to Brewer
Database History From Codd to Brewer
 
(BDT203) From Zero to NoSQL Hero: Amazon DynamoDB Tutorial | AWS re:Invent 2014
(BDT203) From Zero to NoSQL Hero: Amazon DynamoDB Tutorial | AWS re:Invent 2014(BDT203) From Zero to NoSQL Hero: Amazon DynamoDB Tutorial | AWS re:Invent 2014
(BDT203) From Zero to NoSQL Hero: Amazon DynamoDB Tutorial | AWS re:Invent 2014
 

Recently uploaded

April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxolyaivanovalion
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxolyaivanovalion
 
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Onlineanilsa9823
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023ymrp368
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...shambhavirathore45
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 

Recently uploaded (20)

April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptx
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptx
 
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 

Neo4j 20 minutes introduction

  • 2. THE REAL VALUE IS IN THE RELATIONSHIPS • Google : Knowledge Graph • Facebook: Unicorn • Twitter: flockdb • ....
  • 3. WHAT IS THE PROBLEM WITH RDBMS? (PART 1) The base question of all recommendation systems: “User 99 has bought the products 1, 2, 3 and 765 so far. Get the list of other products bought by other users together with the products 1, 2, 3 or 765 in descending order by popularity”
  • 4. WHAT IS THE PROBLEM WITH RDBMS? (PART 2) “Who are Bob’s friends-of-friends-of-friends?” “What is the shortest path between two specific friends?” ...?
  • 5. BASICS: WHAT IS A GRAPH? • Origin: Euler 18th century • It contains nodes and relationships. • Nodes contain properties (key-value pairs). • Nodes can be labeled with one or more labels. • Relationships are named and directed, and always have a start and end node. • Relationships can also contain properties.
  • 6. GRAPH DATABASES ON THE MARKET • Non-native storage: data in general purpose DB • Native processing: index-free
  • 7. SOCIAL NETWORK SPEED TEST 1 000 000 people each with approximately 50 friends:
  • 8. USE CASES * • Fraud Detection • Graph-Based Search • Identity and Access Management • Master Data Management • Network and IT Operations • Real-Time Recommendations • Social Network * Detailed examples from Neo4j
  • 9. DATA MODELING • concept -> logical model -> physical model • big gap between concept and DB • structure and data volume determines query speed • hard to change schema • concept directly to DB • no gap between concept and DB • query speed not influenced by structure or data volume • easy to change connections
  • 10. CYPHER – GRAPH DATABASE QUERY LANGUAGE Name: Joe Name: Bob FRIEND Person Person (:Person{name:”Joe”})-[:FRIEND]->(:Person{name:”Bob”}) • Other query languages: SPARQL, Gremlin ... • Case sensitive • Most human friendly
  • 11. CREATING SOME TEST DATA IN CYPHER // creating nodes create(:Person{name:"Tom Hanks"}); .... // creating relation between two specific nodes match (a:Person),(b:Movie) where a.name='Ron Howard' and b.title = 'The Da Vinci Code' create (a)-[r:DIRECTED]->(b) return r; .... // set relation property match(Person{name:"Tom Hanks"})-[n:KNOWS]-> (Person{name:„Ron Howard"}) set n.since=1987; .... // delete relation match (a)-[r:KNOWS]->(b) where a.name='Matt Damon' and b.name='Matt Damon' delete r;
  • 12. QUERYING DATA IN CYPHER // whom does Tom Hanks know? match (:Person{name:"Tom Hanks"})-[r:KNOWS]->(b) return b; // who knows Steven Spielberg? match (:Person{name:"Steven Spielberg"})<-[:KNOWS]-(b) return b; // which films has Tom Hanks Acted in? match (:Person{name:"Tom Hanks"})-[:ACTED_IN]-(b) return b; // delete by id match (n) where ID(n)=11 delete n; // get Steven Spielberg aquantances 3 levels deep match (:Person{name:"Steven Spielberg"}) -[:KNOWS]-(b) -[:KNOWS]-(c) -[:KNOWS]-(d) return b, c, d
  • 13. A BIGGER EXAMPLE MATCH (tom:Person {name:"Tom Hanks"}) -[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors) RETURN tom, m, coActors Tom Hanks’ co-actors:
  • 14. FINDING THE SHORTEST PATH MATCH p=shortestPath( (kevin:Person {name:"Kevin Bacon"})-[*]-(meg:Person {name:"Meg Ryan"}) ) RETURN p The shortest path between Kevin Bacon and Meg Ryan:
  • 15. RECOMMENDING CO-ACTORS TO TOM HANKS MATCH // coActors: acted in the same movies as Tom // cocoActors: acted in the same movies as coActors but they Tom did not // act in the same movies as the coActors (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors), (coActors)-[:ACTED_IN]->(m2)<-[:ACTED_IN]-(cocoActors) WHERE NOT (tom)-[:ACTED_IN]->(m2) RETURN cocoActors.name AS Recommended, // strength: how many times the same cocoActor was found count(*) AS Strength ORDER BY Strength DESC Find co-actors who haven't work with Tom Hanks (co-co-actors): Tom m (movie) ACTED_IN coActor ACTED_IN m2 (movie) ACTED_IN cocoActor ACTED_IN ACTED_IN
  • 16. NEO4J CLUSTER ARCHITECTURE • Automatic master election • Possible to write to slaves, but it is faster to the master • Full replication (/data redundancy); graph sharding is under development • Single server capacity: 34 billion nodes, 34 billion relationships, 65 thousands relationship types and 68 billion properties • Cluster requires a quorum in order to serve write load • Reads done on slaves : reads scale linearly • Exceptionally high write loads: queing and vertical scaling • Large graph that does not fit in RAM: cache sharding by routing queries • Online backups full / incremental supported • Reporting instances are slaves that will never be elected to be master
  • 17. DEVELOPMENT Query tuning: • execution plan • profiling Indexing on properties Accessing: • web interface • REST API • shell • embedding in Java applications • Mazerunner extension (Using Apache Spark and Neo4j for Big Data Graph Analytics) Utilities • neo4j-shell • neo4j-import • neo4j-backup • neo4j-arbiter
  • 18. RESOURCES Good official manual From Relational to Graph: A Developer's Guide

Editor's Notes

  1. Blue: RDBMS vs Neo4j experience