Transcript
Page 1: Graph databases - EuroPython 2014

Graph DatabasesA little connected tour

Francisco Fernández Castaño

!

@fcofdezc

Page 2: Graph databases - EuroPython 2014

Beginning

Page 3: Graph databases - EuroPython 2014
Page 4: Graph databases - EuroPython 2014

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?

Page 5: Graph databases - EuroPython 2014

El origenG = (V, E)

Page 6: Graph databases - EuroPython 2014
Page 7: Graph databases - EuroPython 2014

What is a Graph DB?

Page 8: Graph databases - EuroPython 2014

Graph

Nodes Relationships

Properties

Stor

e Store

Connect

HaveHave

Page 9: Graph databases - EuroPython 2014

Written in Java

ACID

Rest interface

Cypher

Page 10: Graph databases - EuroPython 2014

Why Graph DB?

Page 11: Graph databases - EuroPython 2014

The traditional way in the context of connected data is artificial

Page 12: Graph databases - EuroPython 2014

!Scalability

Page 13: Graph databases - EuroPython 2014

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

Page 14: Graph databases - EuroPython 2014

Person

Id Person

1 Frank

2 John

.. …

99 Alice

PersonFriend

PersonID FriendID

1 2

2 1

.. …

99 2

Page 15: Graph databases - EuroPython 2014

O(log n)

Page 16: Graph databases - EuroPython 2014

O(1)

Page 17: Graph databases - EuroPython 2014

O(m log n)

Page 18: Graph databases - EuroPython 2014

O(m)

Page 19: Graph databases - EuroPython 2014

We can transform our domain model in a natural way

Page 20: Graph databases - EuroPython 2014
Page 21: Graph databases - EuroPython 2014

Use cases

Page 22: Graph databases - EuroPython 2014

Social Networks

Follow

Follow

John Jeff

Douglas

Page 23: Graph databases - EuroPython 2014

Geospatial problems

Fraud detection

Authorization

Network management

Page 24: Graph databases - EuroPython 2014

Recommendation System

Page 25: Graph databases - EuroPython 2014

CypherDeclarative language

ASCII oriented

Pattern matching

Page 26: Graph databases - EuroPython 2014

CypherCypher

Traverser API

Core API

Kernel

Page 27: Graph databases - EuroPython 2014

Cypher

a b

(a)-->(b)

Page 28: Graph databases - EuroPython 2014

Cypher

clapton cream

(clapton)-[:play_in]->(cream)

play_in

Page 29: Graph databases - EuroPython 2014

Follow

FollowJohn Jeff

Douglas

Cypher

(john:User)-[:FOLLOW]->(jeff:User)!

(douglas:User)-[:FOLLOW]->(john:User)

Page 30: Graph databases - EuroPython 2014

Cypher

clapton {name: Eric Clapton}

cream

(clapton)-[:play_in]->(cream)<-[:labeled]-(blues)

play_in {date: 1968}

Blues

labeled

Page 31: Graph databases - EuroPython 2014

Cypher

MATCH (m)-[:PLAY_IN]—>(b)RETURN m,b;

Page 32: Graph databases - EuroPython 2014

Cypher

MATCH (m)-[:PLAY_IN]—>(b), (b)<-[:LABELED]-(s)RETURN m.name, t.date, s.name;

Page 33: Graph databases - EuroPython 2014

Cypher

MATCH (c {name: ‘clapton’})-[t:PLAY_IN]—>(b), (b)<-[:LABELED]-(s)RETURN c.name, b.name, s.name;

Page 34: Graph databases - EuroPython 2014

Cypher

MATCH (c {name: ‘clapton’})-[t:PLAY_IN]—>(b), (b)<-[:LABELED]-(e {name: ‘blues’})RETURN c.name, b.name, e.nameORDER BY t.date

Page 35: Graph databases - EuroPython 2014

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

Page 36: Graph databases - EuroPython 2014

Cypher

MATCH (a)-[:KNOW*5]—>(b)

Page 37: Graph databases - EuroPython 2014

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

Page 38: Graph databases - EuroPython 2014

Neo4J extensions

Managed

Unmanaged

Page 39: Graph databases - EuroPython 2014

Neo4J extensions

Managed

Unmanaged

Page 40: Graph databases - EuroPython 2014

Neo4J extensions

Managed

Unmanaged

Page 41: Graph databases - EuroPython 2014

Drivers/Clients

Page 42: Graph databases - EuroPython 2014

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

Page 43: Graph databases - EuroPython 2014

References

Page 44: Graph databases - EuroPython 2014

Neo4J as a service

http://www.graphenedb.com

Page 45: Graph databases - EuroPython 2014
Page 46: Graph databases - EuroPython 2014

Danke


Top Related