application modeling with graph databases
TRANSCRIPT
![Page 1: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/1.jpg)
Application Modelingwith Graph Databases
http://joind.in/6694
![Page 2: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/2.jpg)
@josh_adell
• Software developer: PHP, Javascript, SQL• http://www.dunnwell.com• http://blog.everymansoftware.com
• http://github.com/jadell/neo4jphp• http://frostymug.herokuapp.com
![Page 3: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/3.jpg)
The Problem
![Page 4: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/4.jpg)
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'))))
![Page 5: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/5.jpg)
The Truth
Relational databases aren't very good with relationships
Data
RDBMs
![Page 6: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/6.jpg)
RDBs Use Set Math
![Page 7: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/7.jpg)
Try again?
![Page 8: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/8.jpg)
Right Tool for the Job
=
![Page 9: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/9.jpg)
![Page 10: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/10.jpg)
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.
![Page 11: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/11.jpg)
Graphs are Everywhere
![Page 12: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/12.jpg)
Relational Databases are Graphs!
![Page 13: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/13.jpg)
Everything is connected
![Page 14: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/14.jpg)
Some Graph Use Cases
• Social networking• Manufacturing• Map directions• Geo-spatial algorithms• Fraud detection• Multi-tenancy• Dependency mapping• Bioinformatics• Natural language processing
![Page 15: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/15.jpg)
Graphs are "Whiteboard-Friendly"
Nouns => nodes, Verbs => relationships
![Page 16: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/16.jpg)
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
![Page 17: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/17.jpg)
ACL
• Users can belong to groups• Groups can belong to groups• Groups and users have permissions on objects
o reado writeo denied
![Page 18: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/18.jpg)
START u=node:users(name="User 3")MATCH u-[:belongs_to*]->gRETURN g
http://tinyurl.com/cyn3rkx
![Page 19: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/19.jpg)
START u=node:users(name="User 2"), o=node:objects(name="Home")MATCH u-[:belongs_to*0..]->g, g-[:can_read]->oRETURN g http://tinyurl.com/dx7onro
![Page 20: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/20.jpg)
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*]->oWHERE d is nullRETURN g
http://tinyurl.com/bwtyhvt
![Page 21: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/21.jpg)
Real Life Example
• Companies have brands, locations, location groups• Brands have locations, location groups• Location groups have locations
![Page 22: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/22.jpg)
START c=node:companies(name="Company 1")MATCH c-[:HAS*]->lWHERE l.type = 'location'RETURN l ORDER BY l.name
http://tinyurl.com/cxm4heh
![Page 23: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/23.jpg)
START b=node:brands(name="Brand 1")MATCH b<-[:HAS*]-c-[:HAS*]->l<-[h?:HAS*]-bWHERE h IS NULL AND l.type='location'RETURN l ORDER BY l.name
http://tinyurl.com/cl537w6
![Page 24: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/24.jpg)
Tweet
@chicken_tech
we should be using graph dbs!
![Page 25: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/25.jpg)
But Wait...There's More!
• Mutating Cypher (insert, update)• Indexing (auto, full-text, spatial)• Batches and Transactions• Embedded (for JVM) or REST
![Page 26: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/26.jpg)
Where fore art thou, RDB?
• Aggregation• Ordered data• Truly tabular data• Few or clearly defined relationships
![Page 27: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/27.jpg)
Questions?
![Page 28: Application Modeling with Graph Databases](https://reader035.vdocuments.site/reader035/viewer/2022081513/55562dc5d8b42a28608b4ae5/html5/thumbnails/28.jpg)
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