SlideShare une entreprise Scribd logo
1  sur  63
Télécharger pour lire hors ligne
BETTING THE COMPANY 
(AGAIN?!) ON A 
GRAPH DATABASE 
THE STORY CONTINUED… 
Aseem Kishore 
Oct 2014
MIX GRAPHS 
BRINGING IDEAS TOGETHER
MIX NEO4J
MIX GRAPHS
STREAMS 
MATCH (me:User {id: {id}}) 
MATCH (me) <-[:creator]- (creation) 
RETURN creation
PAGINATION (BAD) 
MATCH (me:User {id: {id}}) 
MATCH (me) <-[:creator]- (creation) 
RETURN creation 
ORDER BY creation.createdAt DESC 
SKIP {count} * {page - 1} 
LIMIT {count}
PAGINATION (GOOD) 
MATCH (me:User {id: {id}}) 
MATCH (me) <-[:creator]- (creation) 
WHERE creation.createdAt < {cursorTime} 
RETURN creation 
ORDER BY creation.createdAt DESC 
LIMIT {count}
REMIX FAMILIES 
MATCH (c:Creation {id: {id}}) 
MATCH (c) -[:remix_source*0..]- (relative) 
WHERE relative.createdAt < {cursorTime} 
RETURN relative 
ORDER BY relative.createdAt DESC 
LIMIT {count}
HOME STREAM 1 
MATCH (me:User {id: {id}}) 
MATCH (me) -[:follows]-> (f) <-[:creator]- (creation) 
WHERE creation.createdAt < {cursorTime} 
RETURN creation 
ORDER BY creation.createdAt DESC 
LIMIT {count}
HOME STREAM 2 
MATCH (me:User {id: {id}}) 
MATCH (me) -[:follows]-> (f) -[star:starred]-> (creation) 
WITH creation, star 
ORDER BY star.createdAt 
WITH creation, HEAD(COLLECT(star)) AS star 
WHERE star.createdAt < {cursorTime} 
RETURN creation, star.createdAt AS _starredAt 
ORDER BY _starredAt DESC 
LIMIT {count}
HOME STREAM 3 
MATCH (me:User {id: {id}}) 
MATCH (me) -[:starred]-> (c) <-[:remix_source*]- (remix) 
WHERE remix.createdAt < {cursorTime} 
RETURN DISTINCT remix 
ORDER BY remix.createdAt DESC 
LIMIT {count}
UNION?
UNTIL THEN… 
nodes = _(results).chain().flatten() 
.sortBy (node) -> node._orderedAt 
.unique (node) -> node.id 
.reverse().value() 
Post-processing on our server.
DEDUPING (VERY BAD) 
MATCH (me:User {id: {id}}) 
MATCH (me) -[:follows]-> (f) -[star:starred]-> (creation) 
WITH me, creation, star 
ORDER BY star.createdAt 
WITH me, creation, HEAD(COLLECT(star)) AS star 
MATCH (creation) -[:creator]-> (creator) 
WHERE NOT (me) -[:follows*0..1]-> (creator) 
WHERE star.createdAt < {cursorTime} 
RETURN creation, star.createdAt AS _starredAt 
ORDER BY _starredAt DESC 
LIMIT {count}
DEDUPING (BAD) 
MATCH (me:User {id: {id}}) 
MATCH (me) -[:follows]-> (f) -[star:starred]-> (creation) 
WITH me, creation, star 
ORDER BY star.createdAt 
WITH me, creation, HEAD(COLLECT(star)) AS star 
MATCH (creation) -[:creator]-> (creator) 
WHERE creator <> me AND NOT((me) -[:follows]-> (creator)) 
WHERE star.createdAt < {cursorTime} 
RETURN creation, star.createdAt AS _starredAt 
ORDER BY _starredAt DESC 
LIMIT {count}
QUERY PROFILING 
for key, query of queries 
echo "Query '#{key}':" 
# warm-up: 
neo4j.query query, params, _ 
times = [] 
for i in [1..3] 
start = Date.now() 
neo4j.query query, params, _ 
times.push Date.now() - start 
# ... 
echo "Min/median/max: #{min}/#{median}/#{max} ms. 
Mean: #{Math.round mean} ms." 
(Hat-tip Mark Needham)
HOME STREAM 
0-following-ids 27 ms 
1-following-shares 581 ms 
2-following-features 77 ms 
3-following-stars 1386 ms 
4-stars-remixes 189 ms 
5-shares-remixes 81 ms 
All in parallel 1961 ms 
(On my aging MacBook Air, for our ~worst-case user.)
IN PRODUCTION… 
(But still some || mystery to unravel…)
THRESHOLD
THRESHOLD 
MATCH (me:User {id: {id}}) 
WITH me, TOFLOAT(CASE WHEN me.numFollowing < 1 THEN 1 ELSE me.numFollowing END) AS `me.numFollowing` 
WITH me, FLOOR(LOG(3 * `me.numFollowing` / 100) / LOG(3)) AS threshold 
WITH me, (CASE WHEN threshold < 0 THEN 0 ELSE TOINT(threshold) END) + 1 AS threshold 
MATCH (me) -[:follows]-> (following) -[star:starred]-> (creation) 
WITH creation, star, threshold 
ORDER BY star.createdAt 
WITH creation, COLLECT(star) AS stars, threshold 
WHERE LENGTH(stars) >= threshold 
WITH creation, stars[threshold - 1] AS star 
WITH creation, star.createdAt AS _starredAt 
ORDER BY _starredAt DESC 
LIMIT {count} 
MATCH (creation) -[:creator]-> (creator) 
RETURN creation, creator, _starredAt
THANK YOU

Contenu connexe

Tendances

Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
pugpe
 
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Gareth hayes. non alphanumeric javascript-php and shared fuzzingGareth hayes. non alphanumeric javascript-php and shared fuzzing
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Yury Chemerkin
 
Ruby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と HashRuby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と Hash
higaki
 

Tendances (18)

Ruby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and IteratorsRuby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and Iterators
 
Snake in the DOM!
Snake in the DOM!Snake in the DOM!
Snake in the DOM!
 
Ruby's Arrays and Hashes with examples
Ruby's Arrays and Hashes with examplesRuby's Arrays and Hashes with examples
Ruby's Arrays and Hashes with examples
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.5.2 book - Part 52 of 181The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.5.2 book - Part 52 of 181
 
League of Graphs
League of GraphsLeague of Graphs
League of Graphs
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
 
Canvas & Charts
Canvas & ChartsCanvas & Charts
Canvas & Charts
 
The Ring programming language version 1.6 book - Part 43 of 189
The Ring programming language version 1.6 book - Part 43 of 189The Ring programming language version 1.6 book - Part 43 of 189
The Ring programming language version 1.6 book - Part 43 of 189
 
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Gareth hayes. non alphanumeric javascript-php and shared fuzzingGareth hayes. non alphanumeric javascript-php and shared fuzzing
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
 
Angular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental FeatureAngular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental Feature
 
The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184
 
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
 
Ruby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と HashRuby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と Hash
 
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
 
The Ring programming language version 1.3 book - Part 31 of 88
The Ring programming language version 1.3 book - Part 31 of 88The Ring programming language version 1.3 book - Part 31 of 88
The Ring programming language version 1.3 book - Part 31 of 88
 
The Ring programming language version 1.5.1 book - Part 40 of 180
The Ring programming language version 1.5.1 book - Part 40 of 180The Ring programming language version 1.5.1 book - Part 40 of 180
The Ring programming language version 1.5.1 book - Part 40 of 180
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 

En vedette

Graph Search and Discovery for your Dark Data
Graph Search and Discovery for your Dark DataGraph Search and Discovery for your Dark Data
Graph Search and Discovery for your Dark Data
Neo4j
 
Graph all the things
Graph all the thingsGraph all the things
Graph all the things
Neo4j
 
Graphs fun vjug2
Graphs fun vjug2Graphs fun vjug2
Graphs fun vjug2
Neo4j
 
GraphTalk Frankfurt - Einführung in Graphdatenbanken
GraphTalk Frankfurt - Einführung in GraphdatenbankenGraphTalk Frankfurt - Einführung in Graphdatenbanken
GraphTalk Frankfurt - Einführung in Graphdatenbanken
Neo4j
 

En vedette (20)

GraphConnect 2014 SF: The Business Graph
GraphConnect 2014 SF: The Business GraphGraphConnect 2014 SF: The Business Graph
GraphConnect 2014 SF: The Business Graph
 
GraphTalk Frankfurt - Master Data Management bei der Bayerischen Versicherung
GraphTalk Frankfurt - Master Data Management bei der Bayerischen VersicherungGraphTalk Frankfurt - Master Data Management bei der Bayerischen Versicherung
GraphTalk Frankfurt - Master Data Management bei der Bayerischen Versicherung
 
Graph Search and Discovery for your Dark Data
Graph Search and Discovery for your Dark DataGraph Search and Discovery for your Dark Data
Graph Search and Discovery for your Dark Data
 
Graph your business
Graph your businessGraph your business
Graph your business
 
GraphConnect 2014 SF: Neo4j at Scale using Enterprise Integration Patterns
GraphConnect 2014 SF: Neo4j at Scale using Enterprise Integration PatternsGraphConnect 2014 SF: Neo4j at Scale using Enterprise Integration Patterns
GraphConnect 2014 SF: Neo4j at Scale using Enterprise Integration Patterns
 
Metadata and Access Control
Metadata and Access ControlMetadata and Access Control
Metadata and Access Control
 
Graph all the things
Graph all the thingsGraph all the things
Graph all the things
 
Neo4j Makes Graphs Easy
Neo4j Makes Graphs EasyNeo4j Makes Graphs Easy
Neo4j Makes Graphs Easy
 
Neo4j Makes Graphs Easy? - GraphDay AmandaLaucher
Neo4j Makes Graphs Easy? - GraphDay AmandaLaucherNeo4j Makes Graphs Easy? - GraphDay AmandaLaucher
Neo4j Makes Graphs Easy? - GraphDay AmandaLaucher
 
Graph Your Business - GraphDay JimWebber
Graph Your Business - GraphDay JimWebberGraph Your Business - GraphDay JimWebber
Graph Your Business - GraphDay JimWebber
 
Transparency One : La (re)découverte de la chaîne d'approvisionnement
Transparency One : La (re)découverte de la chaîne d'approvisionnementTransparency One : La (re)découverte de la chaîne d'approvisionnement
Transparency One : La (re)découverte de la chaîne d'approvisionnement
 
GraphDay Noble/Coolio
GraphDay Noble/CoolioGraphDay Noble/Coolio
GraphDay Noble/Coolio
 
Meetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4jMeetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4j
 
Graphs fun vjug2
Graphs fun vjug2Graphs fun vjug2
Graphs fun vjug2
 
GraphTalk Frankfurt - Einführung in Graphdatenbanken
GraphTalk Frankfurt - Einführung in GraphdatenbankenGraphTalk Frankfurt - Einführung in Graphdatenbanken
GraphTalk Frankfurt - Einführung in Graphdatenbanken
 
GraphTalk - Semantische Netze mit structr
GraphTalk - Semantische Netze mit structrGraphTalk - Semantische Netze mit structr
GraphTalk - Semantische Netze mit structr
 
Graph all the things - PRathle
Graph all the things - PRathleGraph all the things - PRathle
Graph all the things - PRathle
 
GraphTalks - Einführung
GraphTalks - EinführungGraphTalks - Einführung
GraphTalks - Einführung
 
GraphTalk - Semantisches PDM bei Schleich
GraphTalk - Semantisches PDM bei Schleich GraphTalk - Semantisches PDM bei Schleich
GraphTalk - Semantisches PDM bei Schleich
 
RDBMS to Graphs
RDBMS to GraphsRDBMS to Graphs
RDBMS to Graphs
 

Similaire à GraphConnect 2014 SF: Betting the Company on a Graph Database - Part 2

Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
Jeremy Kendall
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
MongoSF
 
Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"
Webmontag Berlin
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About Ruby
Ian Bishop
 

Similaire à GraphConnect 2014 SF: Betting the Company on a Graph Database - Part 2 (20)

Graph Search: The Power of Connected Data
Graph Search: The Power of Connected DataGraph Search: The Power of Connected Data
Graph Search: The Power of Connected Data
 
Optimizing Cypher Queries in Neo4j
Optimizing Cypher Queries in Neo4jOptimizing Cypher Queries in Neo4j
Optimizing Cypher Queries in Neo4j
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls
 
Tips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query PitfallsTips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query Pitfalls
 
Cassandra Day London 2015: Getting Started with Apache Cassandra and Java
Cassandra Day London 2015: Getting Started with Apache Cassandra and JavaCassandra Day London 2015: Getting Started with Apache Cassandra and Java
Cassandra Day London 2015: Getting Started with Apache Cassandra and Java
 
Cassandra Day London: Building Java Applications
Cassandra Day London: Building Java ApplicationsCassandra Day London: Building Java Applications
Cassandra Day London: Building Java Applications
 
Grails: a quick tutorial (1)
Grails: a quick tutorial (1)Grails: a quick tutorial (1)
Grails: a quick tutorial (1)
 
Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wild
 
ScalikeJDBC Tutorial for Beginners
ScalikeJDBC Tutorial for BeginnersScalikeJDBC Tutorial for Beginners
ScalikeJDBC Tutorial for Beginners
 
Pitfalls to Avoid for Cascade Server Newbies by Lisa Hall
Pitfalls to Avoid for Cascade Server Newbies by Lisa HallPitfalls to Avoid for Cascade Server Newbies by Lisa Hall
Pitfalls to Avoid for Cascade Server Newbies by Lisa Hall
 
Neo4j: Import and Data Modelling
Neo4j: Import and Data ModellingNeo4j: Import and Data Modelling
Neo4j: Import and Data Modelling
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Pg Conf - Implementing Graph Database based-on PostgreSQL
Pg Conf - Implementing Graph Database based-on PostgreSQLPg Conf - Implementing Graph Database based-on PostgreSQL
Pg Conf - Implementing Graph Database based-on PostgreSQL
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About Ruby
 

Plus de Neo4j

Plus de Neo4j (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
QIAGEN: Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
QIAGEN: Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansQIAGEN: Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
QIAGEN: Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
ISDEFE - GraphSummit Madrid - ARETA: Aviation Real-Time Emissions Token Accre...
ISDEFE - GraphSummit Madrid - ARETA: Aviation Real-Time Emissions Token Accre...ISDEFE - GraphSummit Madrid - ARETA: Aviation Real-Time Emissions Token Accre...
ISDEFE - GraphSummit Madrid - ARETA: Aviation Real-Time Emissions Token Accre...
 
BBVA - GraphSummit Madrid - Caso de éxito en BBVA: Optimizando con grafos
BBVA - GraphSummit Madrid - Caso de éxito en BBVA: Optimizando con grafosBBVA - GraphSummit Madrid - Caso de éxito en BBVA: Optimizando con grafos
BBVA - GraphSummit Madrid - Caso de éxito en BBVA: Optimizando con grafos
 
Graph Everywhere - Josep Taruella - Por qué Graph Data Science en tus modelos...
Graph Everywhere - Josep Taruella - Por qué Graph Data Science en tus modelos...Graph Everywhere - Josep Taruella - Por qué Graph Data Science en tus modelos...
Graph Everywhere - Josep Taruella - Por qué Graph Data Science en tus modelos...
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 
Neo4j_Exploring the Impact of Graph Technology on Financial Services.pdf
Neo4j_Exploring the Impact of Graph Technology on Financial Services.pdfNeo4j_Exploring the Impact of Graph Technology on Financial Services.pdf
Neo4j_Exploring the Impact of Graph Technology on Financial Services.pdf
 
Rabobank_Exploring the Impact of Graph Technology on Financial Services.pdf
Rabobank_Exploring the Impact of Graph Technology on Financial Services.pdfRabobank_Exploring the Impact of Graph Technology on Financial Services.pdf
Rabobank_Exploring the Impact of Graph Technology on Financial Services.pdf
 
Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
Neo4j: Data Engineering for RAG (retrieval augmented generation)
Neo4j: Data Engineering for RAG (retrieval augmented generation)Neo4j: Data Engineering for RAG (retrieval augmented generation)
Neo4j: Data Engineering for RAG (retrieval augmented generation)
 
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdfNeo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
 
Enabling GenAI Breakthroughs with Knowledge Graphs
Enabling GenAI Breakthroughs with Knowledge GraphsEnabling GenAI Breakthroughs with Knowledge Graphs
Enabling GenAI Breakthroughs with Knowledge Graphs
 
Neo4j_Anurag Tandon_Product Vision and Roadmap.Benelux.pptx.pdf
Neo4j_Anurag Tandon_Product Vision and Roadmap.Benelux.pptx.pdfNeo4j_Anurag Tandon_Product Vision and Roadmap.Benelux.pptx.pdf
Neo4j_Anurag Tandon_Product Vision and Roadmap.Benelux.pptx.pdf
 
Neo4j Jesus Barrasa The Art of the Possible with Graph
Neo4j Jesus Barrasa The Art of the Possible with GraphNeo4j Jesus Barrasa The Art of the Possible with Graph
Neo4j Jesus Barrasa The Art of the Possible with Graph
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

GraphConnect 2014 SF: Betting the Company on a Graph Database - Part 2

  • 1. BETTING THE COMPANY (AGAIN?!) ON A GRAPH DATABASE THE STORY CONTINUED… Aseem Kishore Oct 2014
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. MIX GRAPHS BRINGING IDEAS TOGETHER
  • 7.
  • 8.
  • 9.
  • 10.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. STREAMS MATCH (me:User {id: {id}}) MATCH (me) <-[:creator]- (creation) RETURN creation
  • 32. PAGINATION (BAD) MATCH (me:User {id: {id}}) MATCH (me) <-[:creator]- (creation) RETURN creation ORDER BY creation.createdAt DESC SKIP {count} * {page - 1} LIMIT {count}
  • 33. PAGINATION (GOOD) MATCH (me:User {id: {id}}) MATCH (me) <-[:creator]- (creation) WHERE creation.createdAt < {cursorTime} RETURN creation ORDER BY creation.createdAt DESC LIMIT {count}
  • 34.
  • 35.
  • 36.
  • 37.
  • 38. REMIX FAMILIES MATCH (c:Creation {id: {id}}) MATCH (c) -[:remix_source*0..]- (relative) WHERE relative.createdAt < {cursorTime} RETURN relative ORDER BY relative.createdAt DESC LIMIT {count}
  • 39.
  • 40.
  • 41.
  • 42. HOME STREAM 1 MATCH (me:User {id: {id}}) MATCH (me) -[:follows]-> (f) <-[:creator]- (creation) WHERE creation.createdAt < {cursorTime} RETURN creation ORDER BY creation.createdAt DESC LIMIT {count}
  • 43. HOME STREAM 2 MATCH (me:User {id: {id}}) MATCH (me) -[:follows]-> (f) -[star:starred]-> (creation) WITH creation, star ORDER BY star.createdAt WITH creation, HEAD(COLLECT(star)) AS star WHERE star.createdAt < {cursorTime} RETURN creation, star.createdAt AS _starredAt ORDER BY _starredAt DESC LIMIT {count}
  • 44. HOME STREAM 3 MATCH (me:User {id: {id}}) MATCH (me) -[:starred]-> (c) <-[:remix_source*]- (remix) WHERE remix.createdAt < {cursorTime} RETURN DISTINCT remix ORDER BY remix.createdAt DESC LIMIT {count}
  • 46.
  • 47.
  • 48. UNTIL THEN… nodes = _(results).chain().flatten() .sortBy (node) -> node._orderedAt .unique (node) -> node.id .reverse().value() Post-processing on our server.
  • 49. DEDUPING (VERY BAD) MATCH (me:User {id: {id}}) MATCH (me) -[:follows]-> (f) -[star:starred]-> (creation) WITH me, creation, star ORDER BY star.createdAt WITH me, creation, HEAD(COLLECT(star)) AS star MATCH (creation) -[:creator]-> (creator) WHERE NOT (me) -[:follows*0..1]-> (creator) WHERE star.createdAt < {cursorTime} RETURN creation, star.createdAt AS _starredAt ORDER BY _starredAt DESC LIMIT {count}
  • 50. DEDUPING (BAD) MATCH (me:User {id: {id}}) MATCH (me) -[:follows]-> (f) -[star:starred]-> (creation) WITH me, creation, star ORDER BY star.createdAt WITH me, creation, HEAD(COLLECT(star)) AS star MATCH (creation) -[:creator]-> (creator) WHERE creator <> me AND NOT((me) -[:follows]-> (creator)) WHERE star.createdAt < {cursorTime} RETURN creation, star.createdAt AS _starredAt ORDER BY _starredAt DESC LIMIT {count}
  • 51. QUERY PROFILING for key, query of queries echo "Query '#{key}':" # warm-up: neo4j.query query, params, _ times = [] for i in [1..3] start = Date.now() neo4j.query query, params, _ times.push Date.now() - start # ... echo "Min/median/max: #{min}/#{median}/#{max} ms. Mean: #{Math.round mean} ms." (Hat-tip Mark Needham)
  • 52. HOME STREAM 0-following-ids 27 ms 1-following-shares 581 ms 2-following-features 77 ms 3-following-stars 1386 ms 4-stars-remixes 189 ms 5-shares-remixes 81 ms All in parallel 1961 ms (On my aging MacBook Air, for our ~worst-case user.)
  • 53. IN PRODUCTION… (But still some || mystery to unravel…)
  • 55.
  • 56. THRESHOLD MATCH (me:User {id: {id}}) WITH me, TOFLOAT(CASE WHEN me.numFollowing < 1 THEN 1 ELSE me.numFollowing END) AS `me.numFollowing` WITH me, FLOOR(LOG(3 * `me.numFollowing` / 100) / LOG(3)) AS threshold WITH me, (CASE WHEN threshold < 0 THEN 0 ELSE TOINT(threshold) END) + 1 AS threshold MATCH (me) -[:follows]-> (following) -[star:starred]-> (creation) WITH creation, star, threshold ORDER BY star.createdAt WITH creation, COLLECT(star) AS stars, threshold WHERE LENGTH(stars) >= threshold WITH creation, stars[threshold - 1] AS star WITH creation, star.createdAt AS _starredAt ORDER BY _starredAt DESC LIMIT {count} MATCH (creation) -[:creator]-> (creator) RETURN creation, creator, _starredAt
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.