SlideShare a Scribd company logo
Application Modeling
with Graph Databases



              http://joind.in/6694
@josh_adell

• Software developer: PHP, Javascript, SQL
• http://www.dunnwell.com
• http://blog.everymansoftware.com

• http://github.com/jadell/neo4jphp
• http://frostymug.herokuapp.com
The Problem
The Solution?

> -- First degree
> SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title
FROM cast WHERE actor_name='Kevin Bacon')

> -- Second degree
> SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title
FROM cast WHERE actor_name IN (SELECT actor_name FROM cast WHERE movie_title IN
(SELECT DISTINCT movie_title FROM cast WHERE actor_name='Kevin Bacon')))

> -- Third degree
> SELECT actor_name FROM cast WHERE movie_title IN(SELECT DISTINCT movie_title
FROM cast WHERE actor_name IN (SELECT actor_name FROM cast WHERE movie_title IN
(SELECT DISTINCT movie_title FROM cast WHERE actor_name IN (SELECT
actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM
cast WHERE actor_name='Kevin Bacon'))))
The Truth

Relational databases aren't very good with relationships


                       Data



                      RDBMs
RDBs Use Set Math
Try again?
Right Tool for the Job



          =
Application Modeling with Graph Databases
Warning: Computer Science Ahead

     A graph is an ordered pair G = (V, E)

       where V is a set of vertices and

            E is a set of edges,
       which are pairs of vertices in V.
Graphs are Everywhere
Relational Databases are Graphs!
Everything is connected
Some Graph Use Cases

•   Social networking
•   Manufacturing
•   Map directions
•   Geo-spatial algorithms
•   Fraud detection
•   Multi-tenancy
•   Dependency mapping
•   Bioinformatics
•   Natural language processing
Graphs are "Whiteboard-Friendly"




   Nouns => nodes, Verbs => relationships
Back to Bacon




START s=node:actors(name="Keanu Reeves"),
      e=node:actors(name="Kevin Bacon")

MATCH p = shortestPath( s-[*]-e )

RETURN p, length(p)
                                            http://tinyurl.com/c65d99w
ACL

• Users can belong to groups
• Groups can belong to groups
• Groups and users have permissions on objects
  o read
  o write
  o denied
START u=node:users(name="User 3")
MATCH u-[:belongs_to*]->g
RETURN g

                                    http://tinyurl.com/cyn3rkx
START u=node:users(name="User 2"),
      o=node:objects(name="Home")
MATCH u-[:belongs_to*0..]->g,
      g-[:can_read]->o
RETURN g
                                     http://tinyurl.com/dx7onro
START u=node:users(name="User 3"),
      o=node:objects(name="Users 1 Blog")
MATCH u-[:belongs_to*0..]->g,
      g-[:can_read]->o,
      u-[d?:denied*]->o
WHERE d is null
RETURN g
                                            http://tinyurl.com/bwtyhvt
Real Life Example

• Companies have brands, locations, location groups
• Brands have locations, location groups
• Location groups have locations
START c=node:companies(name="Company 1")
MATCH c-[:HAS*]->l
WHERE l.type = 'location'
RETURN l ORDER BY l.name
                                           http://tinyurl.com/cxm4heh
START b=node:brands(name="Brand 1")
MATCH b<-[:HAS*]-c-[:HAS*]->l<-[h?:HAS*]-b
WHERE h IS NULL AND l.type='location'
RETURN l ORDER BY l.name
                                         http://tinyurl.com/cl537w6
Tweet

    @chicken_tech
we should be using graph dbs!
But Wait...There's More!

•   Mutating Cypher (insert, update)
•   Indexing (auto, full-text, spatial)
•   Batches and Transactions
•   Embedded (for JVM) or REST
Where fore art thou, RDB?

•   Aggregation
•   Ordered data
•   Truly tabular data
•   Few or clearly defined relationships
Questions?
Resources

• http://joind.in/6694

• http://neo4j.org
• http://docs.neo4j.org
• http://www.youtube.com/watch?v=UodTzseLh04

• http://github.com/jadell/neo4jphp

•   http://joshadell.com
•   josh.adell@gmail.com
•   @josh_adell
•   Google+, Facebook, LinkedIn
Ad

Recommended

Introduction to Graph Databases
Introduction to Graph Databases
Josh Adell
 
A new data platform for Parliament
A new data platform for Parliament
UK Parliament Data
 
Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)
Pamela Fox
 
You are in a maze of deeply nested maps, all alike
You are in a maze of deeply nested maps, all alike
Eric Normand
 
GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...
GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...
Marcel Caraciolo
 
Maintaining your own branch of Drupal core
Maintaining your own branch of Drupal core
drumm
 
Ruby - Uma Introdução
Ruby - Uma Introdução
Ígor Bonadio
 
Software Dendrology by Brandon Bloom
Software Dendrology by Brandon Bloom
Hakka Labs
 
Talk to me – Chatbots und digitale Assistenten
Talk to me – Chatbots und digitale Assistenten
inovex GmbH
 
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
Alberto Paro
 
2017 02-07 - elastic & spark. building a search geo locator
2017 02-07 - elastic & spark. building a search geo locator
Alberto Paro
 
Seattle.rb 6.4
Seattle.rb 6.4
deanhudson
 
Manifests of Future Past
Manifests of Future Past
Puppet
 
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Arc & Codementor
 
20171014 tips for manipulating filesystem in julia
20171014 tips for manipulating filesystem in julia
岳華 杜
 
Elegant APIs
Elegant APIs
Andrew Timberlake
 
Persona-fication or: Falling in Love with a Bot
Persona-fication or: Falling in Love with a Bot
Modern Hombre
 
The Long Term Investment Outlook for China
The Long Term Investment Outlook for China
John M Olson, CLTC
 
لوحة الجيوب
لوحة الجيوب
boba56222
 
Building Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstep
guest9efd1a1
 
StrongSteam AI at HackerNews London October 2011
StrongSteam AI at HackerNews London October 2011
Ian Ozsvald
 
Boomers to Millennials
Boomers to Millennials
John M Olson, CLTC
 
Investors Need Purchasing Power
Investors Need Purchasing Power
John M Olson, CLTC
 
Data is a Designer's Best Friend - EuroIA 2016
Data is a Designer's Best Friend - EuroIA 2016
Kathryn Parkes
 
Lanyrd Pro
Lanyrd Pro
Lanyrd
 
EuroIA 2016 - Clementina Gentile - Hello stranger
EuroIA 2016 - Clementina Gentile - Hello stranger
Clementina Gentile
 
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
kgrandis
 
Applying Computer Vision to Art History
Applying Computer Vision to Art History
jeresig
 
Design your application using Persistent Graphs and OrientDB
Design your application using Persistent Graphs and OrientDB
Luca Garulli
 
Neo4j - graph database for recommendations
Neo4j - graph database for recommendations
proksik
 

More Related Content

What's hot (8)

Talk to me – Chatbots und digitale Assistenten
Talk to me – Chatbots und digitale Assistenten
inovex GmbH
 
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
Alberto Paro
 
2017 02-07 - elastic & spark. building a search geo locator
2017 02-07 - elastic & spark. building a search geo locator
Alberto Paro
 
Seattle.rb 6.4
Seattle.rb 6.4
deanhudson
 
Manifests of Future Past
Manifests of Future Past
Puppet
 
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Arc & Codementor
 
20171014 tips for manipulating filesystem in julia
20171014 tips for manipulating filesystem in julia
岳華 杜
 
Elegant APIs
Elegant APIs
Andrew Timberlake
 
Talk to me – Chatbots und digitale Assistenten
Talk to me – Chatbots und digitale Assistenten
inovex GmbH
 
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
Alberto Paro
 
2017 02-07 - elastic & spark. building a search geo locator
2017 02-07 - elastic & spark. building a search geo locator
Alberto Paro
 
Seattle.rb 6.4
Seattle.rb 6.4
deanhudson
 
Manifests of Future Past
Manifests of Future Past
Puppet
 
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Arc & Codementor
 
20171014 tips for manipulating filesystem in julia
20171014 tips for manipulating filesystem in julia
岳華 杜
 

Viewers also liked (20)

Persona-fication or: Falling in Love with a Bot
Persona-fication or: Falling in Love with a Bot
Modern Hombre
 
The Long Term Investment Outlook for China
The Long Term Investment Outlook for China
John M Olson, CLTC
 
لوحة الجيوب
لوحة الجيوب
boba56222
 
Building Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstep
guest9efd1a1
 
StrongSteam AI at HackerNews London October 2011
StrongSteam AI at HackerNews London October 2011
Ian Ozsvald
 
Boomers to Millennials
Boomers to Millennials
John M Olson, CLTC
 
Investors Need Purchasing Power
Investors Need Purchasing Power
John M Olson, CLTC
 
Data is a Designer's Best Friend - EuroIA 2016
Data is a Designer's Best Friend - EuroIA 2016
Kathryn Parkes
 
Lanyrd Pro
Lanyrd Pro
Lanyrd
 
EuroIA 2016 - Clementina Gentile - Hello stranger
EuroIA 2016 - Clementina Gentile - Hello stranger
Clementina Gentile
 
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
kgrandis
 
Applying Computer Vision to Art History
Applying Computer Vision to Art History
jeresig
 
Design your application using Persistent Graphs and OrientDB
Design your application using Persistent Graphs and OrientDB
Luca Garulli
 
Neo4j - graph database for recommendations
Neo4j - graph database for recommendations
proksik
 
The Graph Traversal Programming Pattern
The Graph Traversal Programming Pattern
Marko Rodriguez
 
Graphs in the Database: Rdbms In The Social Networks Age
Graphs in the Database: Rdbms In The Social Networks Age
Lorenzo Alberton
 
Intro to Neo4j presentation
Intro to Neo4j presentation
jexp
 
Working With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and Modeling
Neo4j
 
NoSQL Databases: Why, what and when
NoSQL Databases: Why, what and when
Lorenzo Alberton
 
Webinar: RDBMS to Graphs
Webinar: RDBMS to Graphs
Neo4j
 
Persona-fication or: Falling in Love with a Bot
Persona-fication or: Falling in Love with a Bot
Modern Hombre
 
The Long Term Investment Outlook for China
The Long Term Investment Outlook for China
John M Olson, CLTC
 
لوحة الجيوب
لوحة الجيوب
boba56222
 
Building Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstep
guest9efd1a1
 
StrongSteam AI at HackerNews London October 2011
StrongSteam AI at HackerNews London October 2011
Ian Ozsvald
 
Investors Need Purchasing Power
Investors Need Purchasing Power
John M Olson, CLTC
 
Data is a Designer's Best Friend - EuroIA 2016
Data is a Designer's Best Friend - EuroIA 2016
Kathryn Parkes
 
Lanyrd Pro
Lanyrd Pro
Lanyrd
 
EuroIA 2016 - Clementina Gentile - Hello stranger
EuroIA 2016 - Clementina Gentile - Hello stranger
Clementina Gentile
 
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
kgrandis
 
Applying Computer Vision to Art History
Applying Computer Vision to Art History
jeresig
 
Design your application using Persistent Graphs and OrientDB
Design your application using Persistent Graphs and OrientDB
Luca Garulli
 
Neo4j - graph database for recommendations
Neo4j - graph database for recommendations
proksik
 
The Graph Traversal Programming Pattern
The Graph Traversal Programming Pattern
Marko Rodriguez
 
Graphs in the Database: Rdbms In The Social Networks Age
Graphs in the Database: Rdbms In The Social Networks Age
Lorenzo Alberton
 
Intro to Neo4j presentation
Intro to Neo4j presentation
jexp
 
Working With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and Modeling
Neo4j
 
NoSQL Databases: Why, what and when
NoSQL Databases: Why, what and when
Lorenzo Alberton
 
Webinar: RDBMS to Graphs
Webinar: RDBMS to Graphs
Neo4j
 
Ad

Similar to Application Modeling with Graph Databases (20)

React Native Evening
React Native Evening
Troy Miles
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
Qiangning Hong
 
JIP Pipeline System Introduction
JIP Pipeline System Introduction
thasso23
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
Jeremy Kendall
 
Bioinformatics p5-bioperl v2013-wim_vancriekinge
Bioinformatics p5-bioperl v2013-wim_vancriekinge
Prof. Wim Van Criekinge
 
Hypertable - massively scalable nosql database
Hypertable - massively scalable nosql database
bigdatagurus_meetup
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
Jonathan Felch
 
Bioinformatica p6-bioperl
Bioinformatica p6-bioperl
Prof. Wim Van Criekinge
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query Language
Neo4j
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
Matt Stine
 
Hands On Spring Data
Hands On Spring Data
Eric Bottard
 
Async. and Realtime Geo Applications with Node.js
Async. and Realtime Geo Applications with Node.js
Shoaib Burq
 
CakePHP
CakePHP
Walther Lalk
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
Michelangelo van Dam
 
JavaScript for Flex Devs
JavaScript for Flex Devs
Aaronius
 
Make BDD great again
Make BDD great again
Yana Gusti
 
Go Web Development
Go Web Development
Cheng-Yi Yu
 
Introductionto fp with groovy
Introductionto fp with groovy
Isuru Samaraweera
 
Rails and alternative ORMs
Rails and alternative ORMs
Jonathan Dahl
 
Lighting talk neo4j fosdem 2011
Lighting talk neo4j fosdem 2011
Jordi Valverde
 
React Native Evening
React Native Evening
Troy Miles
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
Qiangning Hong
 
JIP Pipeline System Introduction
JIP Pipeline System Introduction
thasso23
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
Jeremy Kendall
 
Bioinformatics p5-bioperl v2013-wim_vancriekinge
Bioinformatics p5-bioperl v2013-wim_vancriekinge
Prof. Wim Van Criekinge
 
Hypertable - massively scalable nosql database
Hypertable - massively scalable nosql database
bigdatagurus_meetup
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
Jonathan Felch
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query Language
Neo4j
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
Matt Stine
 
Hands On Spring Data
Hands On Spring Data
Eric Bottard
 
Async. and Realtime Geo Applications with Node.js
Async. and Realtime Geo Applications with Node.js
Shoaib Burq
 
JavaScript for Flex Devs
JavaScript for Flex Devs
Aaronius
 
Make BDD great again
Make BDD great again
Yana Gusti
 
Go Web Development
Go Web Development
Cheng-Yi Yu
 
Introductionto fp with groovy
Introductionto fp with groovy
Isuru Samaraweera
 
Rails and alternative ORMs
Rails and alternative ORMs
Jonathan Dahl
 
Lighting talk neo4j fosdem 2011
Lighting talk neo4j fosdem 2011
Jordi Valverde
 
Ad

Recently uploaded (20)

Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 

Application Modeling with Graph Databases

  • 1. Application Modeling with Graph Databases http://joind.in/6694
  • 2. @josh_adell • Software developer: PHP, Javascript, SQL • http://www.dunnwell.com • http://blog.everymansoftware.com • http://github.com/jadell/neo4jphp • http://frostymug.herokuapp.com
  • 4. The Solution? > -- First degree > SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM cast WHERE actor_name='Kevin Bacon') > -- Second degree > SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM cast WHERE actor_name IN (SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM cast WHERE actor_name='Kevin Bacon'))) > -- Third degree > SELECT actor_name FROM cast WHERE movie_title IN(SELECT DISTINCT movie_title FROM cast WHERE actor_name IN (SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM cast WHERE actor_name IN (SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM cast WHERE actor_name='Kevin Bacon'))))
  • 5. The Truth Relational databases aren't very good with relationships Data RDBMs
  • 8. Right Tool for the Job =
  • 10. Warning: Computer Science Ahead A graph is an ordered pair G = (V, E) where V is a set of vertices and E is a set of edges, which are pairs of vertices in V.
  • 14. Some Graph Use Cases • Social networking • Manufacturing • Map directions • Geo-spatial algorithms • Fraud detection • Multi-tenancy • Dependency mapping • Bioinformatics • Natural language processing
  • 15. Graphs are "Whiteboard-Friendly" Nouns => nodes, Verbs => relationships
  • 16. Back to Bacon START s=node:actors(name="Keanu Reeves"), e=node:actors(name="Kevin Bacon") MATCH p = shortestPath( s-[*]-e ) RETURN p, length(p) http://tinyurl.com/c65d99w
  • 17. ACL • Users can belong to groups • Groups can belong to groups • Groups and users have permissions on objects o read o write o denied
  • 18. START u=node:users(name="User 3") MATCH u-[:belongs_to*]->g RETURN g http://tinyurl.com/cyn3rkx
  • 19. START u=node:users(name="User 2"), o=node:objects(name="Home") MATCH u-[:belongs_to*0..]->g, g-[:can_read]->o RETURN g http://tinyurl.com/dx7onro
  • 20. START u=node:users(name="User 3"), o=node:objects(name="Users 1 Blog") MATCH u-[:belongs_to*0..]->g, g-[:can_read]->o, u-[d?:denied*]->o WHERE d is null RETURN g http://tinyurl.com/bwtyhvt
  • 21. Real Life Example • Companies have brands, locations, location groups • Brands have locations, location groups • Location groups have locations
  • 22. START c=node:companies(name="Company 1") MATCH c-[:HAS*]->l WHERE l.type = 'location' RETURN l ORDER BY l.name http://tinyurl.com/cxm4heh
  • 23. START b=node:brands(name="Brand 1") MATCH b<-[:HAS*]-c-[:HAS*]->l<-[h?:HAS*]-b WHERE h IS NULL AND l.type='location' RETURN l ORDER BY l.name http://tinyurl.com/cl537w6
  • 24. Tweet @chicken_tech we should be using graph dbs!
  • 25. But Wait...There's More! • Mutating Cypher (insert, update) • Indexing (auto, full-text, spatial) • Batches and Transactions • Embedded (for JVM) or REST
  • 26. Where fore art thou, RDB? • Aggregation • Ordered data • Truly tabular data • Few or clearly defined relationships
  • 28. Resources • http://joind.in/6694 • http://neo4j.org • http://docs.neo4j.org • http://www.youtube.com/watch?v=UodTzseLh04 • http://github.com/jadell/neo4jphp • http://joshadell.com • [email protected] • @josh_adell • Google+, Facebook, LinkedIn

Editor's Notes

  • #2: * Goal here is to inspire further investigation * Not going to go into nuts &amp; bolts * Docs are amazing!
  • #3: * graph db usage poll
  • #4: * Six degrees game * Relational databases can&apos;t easily answer certain types of questions * arbitrary path query * the basic unit of social networking
  • #5: * Each degree adds a join * Increases complexity * Decreases performance * Stop when the actor you&apos;re looking for is in the list
  • #6: * this problem highlights the ugly truth about RDBs * they weren&apos;t designed to handle these types of problems. * RDB relationships join data, but are not data in themselves * arbitrary path query * RDB does &amp;quot;query&amp;quot;, not &amp;quot;path&amp;quot; * certainly not &amp;quot;arbitrary&amp;quot;
  • #7: * Gather everything in the set that matches these criteria, then tell me if this thing is in the set * 1 set, no problem * 2nd set no problem * 3rd set not related to 1st * 4th not related to 2nd * 5th related to 1st and 4th * etc. * Relationships are only available between overlapping sets
  • #8: * avoid schema lock-in * intuitive * ditch digger&apos;s dilemma
  • #9: * Neo4j * AGPL for community * ACID compliant * High Availablity mode * Embedded and REST
  • #10: * Neo4j * AGPL for community * ACID compliant * High Availablity mode * Embedded and REST * Bindings for every language
  • #11: * graph theory * edges can be ordered or unordered pairs * vocab: - vertex -&gt; node - edge -&gt; relationship
  • #12: * Tree data-structures * Networks * Maps * vehicles on streets == packets through network * social networking * manufacturing * fraud detection * supply chain
  • #13: * Make each record a node * Make every foreign key a relationship * RDB indexes are usually stored in a tree structure * Trees are graphs * Why not use RDBs? * The trouble with RDBs is how they are stored in memory and queried   * Require a translation step from memory blocks to graph structure * ORMs hide the problem, but do not solve it * Relationships not first-class citizens * Many problem domains map poorly to rows/tables
  • #14: The zen of graph databases
  • #15: * Social networking - friends of friends of friends of friends * Assembly/Manufacturing - 1 widget contains 3 gadgets each contain 2 gizmos * Map directions - starting at my house find a route to the office that goes past the pub * Multi-tenancy - root node per tenant * all queries start at root * No overlap between graphs = no accidental data spillage * Fraud: track transactions back to origination * Pretty much anything that can be drawn on a whiteboard
  • #16: * Example: retail system * Customer makes Order * Store sells Order * Order contains Items * Supplier supplied Items * Customer rates Items * Did this customer rank supplier X highly? * Which suppliers sell the highest rated items? * Does item A get rated higher when ordered with Item B? * All can be answered with RDBs as well * Not as elegant * Not as performant
  • #17: * Actors are nodes * Movies are nodes * Relationship: Actor is IN a movie * Compare to degree selection join queries
  • #19: * all groups user 3 is a member of directly or inherited
  • #20: * does user 2 have permission to read the home page?
  • #21: * does user 3 have permission to read the user 1&apos;s blog?
  • #23: * Find all locations in company
  • #24: * For a given brand, find all locations not under that brand
  • #27: * RDBs are really good at data aggregation * Set math, duh * Have to traverse the whole graph in order to do aggregation * Truly tabular means not a lot of relationships between the data types * Neo4j guys say: rdb will tell you the salary of everyone in the room; graph db will tell you who will buy you a beer
  • #29: * Emil Eifrem (Neo Tech CEO) webinar * Check out 54 minute mark