Post on 08-Sep-2014
description
Graph DatabasesA little connected tour
Francisco Fernández Castaño
!
@fcofdezc
Beginning
The old town of Königsberg has seven bridges:
Can you take a walk through town, visiting each part of the town and crossing each bridge only once?
El origenG = (V, E)
What is a Graph DB?
Graph
Nodes Relationships
Properties
Stor
e Store
Connect
HaveHave
Written in Java
ACID
Rest interface
Cypher
Why Graph DB?
The traditional way in the context of connected data is artificial
!Scalability
Depth MySQL time (s) Neo4j time (s) Results
2 0.016 0.01 ~2500
3 30.267 0.168 ~110,000
4 1543.505 1.359 ~600,000
5 No Acaba 2.132 ~800,000
MySQL vs Neo4j
* Neo4J in Action
Person
Id Person
1 Frank
2 John
.. …
99 Alice
PersonFriend
PersonID FriendID
1 2
2 1
.. …
99 2
O(log n)
O(1)
O(m log n)
O(m)
We can transform our domain model in a natural way
Use cases
Social Networks
Follow
Follow
John Jeff
Douglas
Geospatial problems
Fraud detection
Authorization
Network management
Recommendation System
CypherDeclarative language
ASCII oriented
Pattern matching
CypherCypher
Traverser API
Core API
Kernel
Cypher
a b
(a)-->(b)
Cypher
clapton cream
(clapton)-[:play_in]->(cream)
play_in
Follow
FollowJohn Jeff
Douglas
Cypher
(john:User)-[:FOLLOW]->(jeff:User)!
(douglas:User)-[:FOLLOW]->(john:User)
Cypher
clapton {name: Eric Clapton}
cream
(clapton)-[:play_in]->(cream)<-[:labeled]-(blues)
play_in {date: 1968}
Blues
labeled
Cypher
MATCH (m)-[:PLAY_IN]—>(b)RETURN m,b;
Cypher
MATCH (m)-[:PLAY_IN]—>(b), (b)<-[:LABELED]-(s)RETURN m.name, t.date, s.name;
Cypher
MATCH (c {name: ‘clapton’})-[t:PLAY_IN]—>(b), (b)<-[:LABELED]-(s)RETURN c.name, b.name, s.name;
Cypher
MATCH (c {name: ‘clapton’})-[t:PLAY_IN]—>(b), (b)<-[:LABELED]-(e {name: ‘blues’})RETURN c.name, b.name, e.nameORDER BY t.date
Cypher
MATCH (c {name: ‘clapton’})-[r:PLAY_IN | PRODUCE]—>(b), (b)<-[:LABELED]-(e {name: ‘blues’})RETURN c.name, b.name, e.nameWHERE r.date > 1968ORDER BY r.date
Cypher
MATCH (a)-[:KNOW*5]—>(b)
MATCH p = (startNode:Station {name: ‘Sol’}) -[rels:CONNECTED_TO*]-> (endNode:Station {name: ‘Retiro’})RETURN p AS shortestPath, reduce(weight=0, r in rels: weight + r.weight) as tWeightORDER BY tWeight ASCLIMIT 1
Neo4J extensions
Managed
Unmanaged
Neo4J extensions
Managed
Unmanaged
Neo4J extensions
Managed
Unmanaged
Drivers/Clients
Instead of just picking a relational database because everyone does, we need to
understand the nature of the data we’re storing and how we want to manipulate it.
Martin Fowler
References
Neo4J as a service
http://www.graphenedb.com
Danke