SlideShare a Scribd company logo
Graph Oriented
Databases
Ciao
ciao
Vai a fare
ciao ciao
Dr. Fabio Fumarola
Outline
• Introduction
• The Lack of relationship for RDBMS and NoSQL
• Graph Databases: Features
• Relations
• Query Language
• Data Modeling with Graphs
• Conclusions
2
Introduction
• We live in a connected world
• Everything is connected: Social Network, Biology,
Bioinformatics
• The NoSQL databases analyzed store data using
aggregate
• Here we compare graph databases with relational
databases and aggregate NOSQL in storing graph
data
3
Three Facts
1. Relational Databases Lack Relationships
1. NoSQL Databases also Lack Relationships
2. Graph Databases Embrace Relationships
4
Relational Databases Lack Relationships
• For decades we tried to accommodate connected,
semi-structured datasets inside relational databases.
• But:
– relational databases are designed to codify tabular
structures
– They struggle when modeling ad hoc exceptional
relationships that are in real world.
5
Relational Databases Lack Relationships
• Relationships in relational database only mean joining tables
• But we want to model the semantic of relationships that
connect real world
• As outlier data multiplies:
1. The structure of the dataset becomes more complex and
less uniform
2. The relational data becomes more complex and less
uniform (large join tables, sparsely populated rows, a lot
o null values)
6
Example of customer-centric orders
• Complex joins
• Foreign key constraints
• Sparse table with null
values
• Reciprocal queries are
costly “What products did a
customer buy?”
7
NoSQL Databases Also Lack
Relationships
• key-value, document, or column-oriented store sets of
disconnected documents/values/columns
• One well-known strategy for adding relationships is to embed
an aggregate’s identifier inside the field belonging to another
aggregate
• But this require joins at the application level
• Some NoSQL have some concept of navigability but it is
expensive for complex joins
8
Example of aggregate oriented orders
• Some properties are
references to foreign
aggregates
• This relationship are
not first-class citizens
• Are not intended as
real realtionships
9
Example of a Small Social Network
• it’s easy to find a user’s
immediate friends
• friendship isn’t always
reflexive
• We can have brute-force
scan across the whole
dataset looking for friends
entries
10
Graph Databases Embrace Relationships
• The previous examples have dealt with implicitly connected
data
• We infer semantic dependencies between entities
• We model the data based on this connections
• Our application have to navigate on this flat and disconnected
data, and deal with slow queries.
• In contrast, in the graph world, connected data is stored as
connected data
11
Example Social Network
12
• The node user:Bob is a
Vertex with a property
Bob
• We also see relations
which are Edges:
• Boss_of
• Friend_of
• Married_to
GRaph DB Features
13
CAP Theorem
14
Consistency
• Since Graph DBs operate on connected nodes, they
could not scale well distributing nodes across
servers.
• There are solutions supporting distribution:
– Neo4j uses one master and several slaves
– OrientDB uses MVCC for distributed eventual data
structures
– TitanDB partition data by using HBase or Cassandra
15
Transactions
• Most of the Graph DB are ACID-compliant
• Before doing an operation we have to start a
transaction.
• Without wrapping operations in a transaction we will
get an Exception.
16
Availability
• Neo4j from version 1.8 achieves availability by
providing for replicated slaves.
• Infinity Graph, FlockDB and TitanDB provides for
distribute storage of the nodes.
• Neo4J uses Zookeeper to keep track of the last
transaction Ids persisted on each slave node and the
current master node
17
Going Into Relations
18
Relations
• Relations in a graph naturally forms paths.
• Querying or traversing the graph involves following a
path.
• A query on the graph is also known as traversing the
graph
• As advantage we can change the traversing
requirements without changing nodes and edges
19
Relations
• In graph databases traversal operation are highly
efficient.
• In the book Neo4j in Action, Partner and Vukotic
perform an experiment comparing relational store
and Neo4j
20
Relations
• In a depth two (friend-of-friend), both relational db and graph
db perform well enough
• But when we do the depth three it clear that relational db can
no longer deal
21
Relations
• Both aggregate store and relational databases perform poorly
because of the index lookups.
• Graphs, on the other hand, use index-free adjacency list to
ensure that traversing connected data is extremely fast.
22
Relations another case study
• Let us consider the
purchase history of a user
as connected data.
• If we notice that users who
buy strawberry ice cream
also buy espresso beans, we
can start to recommend
those beans to users who
normally only buy the ice
cream.
23
Relations and Recommendations
• The previous was a one dimensional
recommendation
• We can join our graph with graph from other
domains.
• For example, we can ask to fine
– “all the flavors of ice cream liked by people who live near a
user, and enjoy espresso, but dislike Brussels sprouts.”
24
Relations and Patterns
• We can use relations to query graph-patterns
• Such pattern-matching queries are:
– extremely difficult to write in SQL
– And are laborious to write against aggregate stores
• In both cases they tend to perform very poorly
• In the other hand, graph databases are optimized for
such kind of queries
25
Query Language
26
Query Language
• Graph DBs support query
languages such as Gremlin,
Cypher and SPARQL
• Gremlin is a DSL for
traversing graphs;
• It can traverse all the graph
databases implementing the
Blueprints
27
1. Indexing: Nodes and Edges
• Indexes are necessary to find the starting node to
being traversal.
• How Indexes works:
– Can index properties of nodes and edges.
– Adds are done in transactions
• Nodes retrieved can be used to raise queries
28
2. Querying In- Out- Relationships
• Having a node we can query both for Incoming and
Outgoing relationships.
• We can apply directional filters on the queries when
querying for relations
29
3. Querying Breadth- Depth-
• Graph databases are really powerful to query for
incoming and outgoing relationships.
• Moreover, we can make the traverser go top-down
or sideways on the graph by using:
– BREADTH_FIRST or
– DEPTH_FIRST
30
4. Querying Paths
• An other good feature of graph databases is
– finding paths between two nodes.
– Determining if there are multiple paths
– finding the shortest path
• Many Graph DBs use algorithms such as the
Dijkstra’s algorithm for finding shortest paths.
31
5. Querying Paths
• Finally, with Graph DBs it is possible to use Match
operator
• The MATCH is used for matching patterns in
relationships
• The WHERE filters the properties on a node or
relationship
• The RETURN specifies what to get in the result set.
32
Data Modeling with Graphs
Intro
33
Data Modeling with Graphs
how do we model the world in graph terms?
34
how do we model the world in
graph terms?
• Formalization of the base model
• Enrich the model
• Testing the model
35
Formalization of the base model
• Modeling is an abstracting activity motivated by a particular
need or goal
• We model in order to define structures that can manipulated.
• There are no natural representations of the world the way it
“really is,”
• There are just many purposeful selections, abstractions, and
simplifications that useful for satisfying a particular goal
36
Formalization of the base model
• Graph data modeling is different from many other
techniques.
• There is a close affinity between logical and physical
models.
• In relational databases we start from a logical model
to arrive to the physical model.
• With graph databases, this gap shrinks considerably.
37
The Graph Model
• A property graph is made up of nodes, relationships,
and properties.
38
Publishing Messages
• We organize messages in order
39
Nodes
Nodes contain properties
•Think of nodes as documents that store properties in
the form of arbitrary key-value pairs.
•The keys are strings and the values are arbitrary data
types.
40
Relationships
Relationships connect and structure nodes.
•A relationship always has a direction, a label, and a
start node and an end node—there are no dangling
relationships.
•Together, a relationship’s direction and label add
semantic clarity to the structuring of nodes.
41
Relationships: Attributes
Like nodes, relationships can also have properties.
•The ability to add properties to relationships is
particularly useful for:
– Providing additional metadata for graph algorithms
– Adding additional semantics to relationships (including
quality and weight),
– and for constraining queries at runtime.
42
Modeling Steps: Outline
• The initial stage of modeling is similar to the first
stage of many other data modeling techniques, that
is:
– to understand and agree on the entities in the domain
– how they interrelate
– and the rules that govern their state transitions
43
Describe the Model in Terms of the
Application’s Needs
• Agile user stories provide a concise means for
expressing an outside-in, user-centered view of the
application needs.
• Here’s an example of a user story for a book review
web application:
– AS A reader who likes a book,
– I WANT to know which books other readers who like the
same book have liked,
– SO THAT I can find other books to read.
44
Describe the Model in Terms of the
Application’s Needs
• This story expresses a user need, which motivates
the shape and content of our data model.
• From a data modeling point of view:
– the AS A clause establishes a context comprising two
entities—a reader and a book—plus the LIKES relationship
that connects them.
– The I WANT clause exposes more LIKES relationships, and
more entities: other readers and other books.
45
Describe the Model in Terms of the
Application’s Needs
• The entities and relationships in analyzing the user
story quickly translate into a simple data model
46
Modeling Rationale
• Use nodes to represent entities
• Use relationships both:
– to express the connections between entities and
– to establish semantic context for each entity
• Use relationship direction to further clarify
relationship semantics
47
Describe the Model: Guidelines
• Use node properties
– to represent entity attributes, plus any necessary entity
metadata, such as timestamps, version numbers, etc
• Use relationship properties
– to express the strength, weight, or quality of a
relationship, plus any necessary relationship metadata,
such as timestamps, version numbers, etc.
48
Modeling Temporal Relations as
Nodes
• When two or more domain entities interact for a
period of time, a fact emerges
• We represent these facts as separate nodes
• In the following examples we show how we might
model facts and actions using intermediate nodes.
49
Example: Employment
Ian was employed as an engineer at Neo Technology
50
Example: Performance
William Hartnell played the Doctor in the story The
Sensorites
51
Example: Emailing
Ian emailed Jim, and copied in Alistair
52
Example:
Timeline Tree
53
A timeline tree showing the broadcast
dates for four episodes of a TV
program
Example: Linked-List
A doubly linked list representing a time-ordered series
of events
54
Iterative and Incremental
• We develop the data model feature by feature, user
story by user story
• This will ensure we identify the relationships our
application will use to query the graph
• With the iterative and incremental delivery of
application features we will be a corrected model
that provides the right abstraction
55
Data Modeling: Enrich
• The next steps diverges from the relational data
methodology
• Instead of transforming a domain model’s graph-like
representation into tables, we enrich it.
• That is, for each entity in our domain, “we ensure
that we’ve captured both the properties and the
connections to neighboring entities necessary to
support our application goals”.
56
Data Modeling: Enrich
• Remember, the domain model is not totally aligned
to reality.
• it is a purposeful abstraction of those aspects of our
domain relevant to our application goals.
• By enriching our domain graph with additional
properties and relationships, we effectively produce
a graph model aligned to our application’s data
needs
57
Data Modeling: Enrich
In graph terms, we are ensuring that:
•each node has the appropriate properties
•every node is in the correct semantic context.
we do this by creating named and directed (and often
attributed) relationships between the nodes to capture
the structural aspects of the domain.
58
Data Modeling: Test
• The next step is to test how suitable it is for
answering realistic queries
• Also if Graph DB are great in supporting evolving
structures there are some design decisions to
consider
• By reviewing the domain model and the resulting
graph model at this early stage, we can avoid these
pitfalls.
59
Data Modeling: Test
• In practice there are two techniques that we can
apply here
• The first, and simplest, is just to check that the graph
reads well.
• We pick a start node, and then follow relationships
to other nodes, reading each node’s role and each
relationship’s name as we go
• Doing so should create sensible sentences
60
Data Modeling: Test
• The second one is to consider queries we’ll run on
the graph.
• To validate that the graph supports the kinds of
queries we expect to run on it, we must describe
those queries.
• Given a described query if we can easily write the
query in Cypher or Gremlin we can be more certain
that the graph meets the needs of our domain.
61
Conclusions
62
Avoid Anti-Patterns
• In the general case, don’t encode entities into relationships.
• It’s also important to realize that graphs are a naturally
additive structure
• It’s quite natural to add facts in terms of domain entities and
how they interrelate adding nodes and relationships
• If we model in accordance with the questions we want to ask
of our data, an accurate representation of the domain will
emerge.
63
When to Use
• Connected Data
• Routing, Dispatch, and Location-based Services
• Recommendation Engines
64
When Not to Use
• When you need to update all or a subset of entities,
for example in analytics
• In situation when you need to apply operations that
work on the global graph
• When you don’t know the starting point of your
query
65

More Related Content

PDF
Big data-analytics-cpe8035
PPTX
Introduction To HBase
PPTX
Introduction to NoSQL Databases
PDF
Building Applications with a Graph Database
PDF
Graph based data models
PPTX
NOSQL Databases types and Uses
PPTX
Introduction to Graph Databases
PDF
NOSQL- Presentation on NoSQL
Big data-analytics-cpe8035
Introduction To HBase
Introduction to NoSQL Databases
Building Applications with a Graph Database
Graph based data models
NOSQL Databases types and Uses
Introduction to Graph Databases
NOSQL- Presentation on NoSQL

What's hot (20)

PDF
Introduction to HBase
PDF
Introduction to Cassandra
PDF
Cassandra Database
PPTX
NoSQL Graph Databases - Why, When and Where
PDF
How Kafka Powers the World's Most Popular Vector Database System with Charles...
PPT
Chapter - 4 Data Mining Concepts and Techniques 2nd Ed slides Han & Kamber
PPT
6 Data Modeling for NoSQL 2/2
PDF
ETL VS ELT.pdf
PPTX
Introduction of data science
PPTX
An Introduction to NOSQL, Graph Databases and Neo4j
PPTX
ENEL Electricity Grids on Neo4j Graph DB
PPT
Schemaless Databases
PDF
Introduction to Neo4j
PPT
An Introduction to Graph Databases
PPTX
Managing and Deploying High Performance Computing Clusters using Windows HPC ...
PDF
NOSQLEU - Graph Databases and Neo4j
ZIP
NoSQL databases
PPTX
An Intro to NoSQL Databases
PDF
NoSQL
PPTX
Graph databases
Introduction to HBase
Introduction to Cassandra
Cassandra Database
NoSQL Graph Databases - Why, When and Where
How Kafka Powers the World's Most Popular Vector Database System with Charles...
Chapter - 4 Data Mining Concepts and Techniques 2nd Ed slides Han & Kamber
6 Data Modeling for NoSQL 2/2
ETL VS ELT.pdf
Introduction of data science
An Introduction to NOSQL, Graph Databases and Neo4j
ENEL Electricity Grids on Neo4j Graph DB
Schemaless Databases
Introduction to Neo4j
An Introduction to Graph Databases
Managing and Deploying High Performance Computing Clusters using Windows HPC ...
NOSQLEU - Graph Databases and Neo4j
NoSQL databases
An Intro to NoSQL Databases
NoSQL
Graph databases
Ad

Viewers also liked (20)

PPT
10b. Graph Databases Lab
PPT
9b. Document-Oriented Databases lab
PPT
11. From Hadoop to Spark 1:2
PPT
11. From Hadoop to Spark 2/2
PPT
Scala and spark
PDF
Approaching Big Data: Lesson Plan
PPT
Hbase an introduction
PPT
8. column oriented databases
PPT
8b. Column Oriented Databases Lab
PPT
PPT
8a. How To Setup HBase with Docker
PPT
8. key value databases laboratory
PDF
Aloha Social Networking Portal - Design Document
PDF
Graph Search: The Power of Connected Data
PDF
A NOSQL Overview And The Benefits Of Graph Databases (nosql east 2009)
PPT
7. Key-Value Databases: In Depth
PDF
Dbta Webinar Realize Value of Big Data with graph 011713
PDF
Graph Databases - Where Do We Do the Modeling Part?
PPTX
Graph Databases for SQL Server Professionals
PPTX
Data Modeling for NoSQL
10b. Graph Databases Lab
9b. Document-Oriented Databases lab
11. From Hadoop to Spark 1:2
11. From Hadoop to Spark 2/2
Scala and spark
Approaching Big Data: Lesson Plan
Hbase an introduction
8. column oriented databases
8b. Column Oriented Databases Lab
8a. How To Setup HBase with Docker
8. key value databases laboratory
Aloha Social Networking Portal - Design Document
Graph Search: The Power of Connected Data
A NOSQL Overview And The Benefits Of Graph Databases (nosql east 2009)
7. Key-Value Databases: In Depth
Dbta Webinar Realize Value of Big Data with graph 011713
Graph Databases - Where Do We Do the Modeling Part?
Graph Databases for SQL Server Professionals
Data Modeling for NoSQL
Ad

Similar to 10. Graph Databases (20)

PPT
5 Data Modeling for NoSQL 1/2
PPTX
NoSQL 5 2_graph Database Edited - Updated.pptx.pptx
PPTX
Introduction to graph databases in term of neo4j
PPTX
Database Introduction to Data Models.pptx
PPTX
Database Models, Client-Server Architecture, Distributed Database and Classif...
PPTX
Relational and non relational database 7
PPTX
Unit 2_DBMS_10.2.22.pptx
PPTX
RELATIONAL MODEL OF DATABASES AND OTHER CONCEPTS OF DATABASES​
PPTX
Graph Databases
PPTX
Design approach
PPT
introduction-to-dbms-unit-1.ppt
PPT
Data Models - Department of Computer Science & Engineering
PPTX
Seeing Graphs - How to successfully visualize connected data
PPTX
No SQL- The Future Of Data Storage
PPTX
Selecting the right database type for your knowledge management needs.
PPT
Chapter-3-Lesson 1 DM/ Data-Models.ppt/pptx
PPT
Fundamentals of Database ppt ch02
PPTX
Distilled Module1_Chapter2_NoSQL.pptx
PPTX
DBMS data modeling.pptx
PPTX
Module 2.3 Document Databases in NoSQL Systems
5 Data Modeling for NoSQL 1/2
NoSQL 5 2_graph Database Edited - Updated.pptx.pptx
Introduction to graph databases in term of neo4j
Database Introduction to Data Models.pptx
Database Models, Client-Server Architecture, Distributed Database and Classif...
Relational and non relational database 7
Unit 2_DBMS_10.2.22.pptx
RELATIONAL MODEL OF DATABASES AND OTHER CONCEPTS OF DATABASES​
Graph Databases
Design approach
introduction-to-dbms-unit-1.ppt
Data Models - Department of Computer Science & Engineering
Seeing Graphs - How to successfully visualize connected data
No SQL- The Future Of Data Storage
Selecting the right database type for your knowledge management needs.
Chapter-3-Lesson 1 DM/ Data-Models.ppt/pptx
Fundamentals of Database ppt ch02
Distilled Module1_Chapter2_NoSQL.pptx
DBMS data modeling.pptx
Module 2.3 Document Databases in NoSQL Systems

More from Fabio Fumarola (9)

PPT
9. Document Oriented Databases
PPT
2 Linux Container and Docker
PDF
1. Introduction to the Course "Designing Data Bases with Advanced Data Models...
PPT
An introduction to maven gradle and sbt
PPT
Develop with linux containers and docker
PPT
Linux containers and docker
PPTX
08 datasets
PPTX
A Parallel Algorithm for Approximate Frequent Itemset Mining using MapReduce
PPT
NoSQL databases pros and cons
9. Document Oriented Databases
2 Linux Container and Docker
1. Introduction to the Course "Designing Data Bases with Advanced Data Models...
An introduction to maven gradle and sbt
Develop with linux containers and docker
Linux containers and docker
08 datasets
A Parallel Algorithm for Approximate Frequent Itemset Mining using MapReduce
NoSQL databases pros and cons

Recently uploaded (20)

PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPT
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
PPTX
Major-Components-ofNKJNNKNKNKNKronment.pptx
PDF
Mega Projects Data Mega Projects Data
PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
PPTX
Computer network topology notes for revision
PDF
Launch Your Data Science Career in Kochi – 2025
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PDF
Lecture1 pattern recognition............
PDF
.pdf is not working space design for the following data for the following dat...
PPTX
05. PRACTICAL GUIDE TO MICROSOFT EXCEL.pptx
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
1_Introduction to advance data techniques.pptx
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPTX
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
PPTX
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
Major-Components-ofNKJNNKNKNKNKronment.pptx
Mega Projects Data Mega Projects Data
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
Computer network topology notes for revision
Launch Your Data Science Career in Kochi – 2025
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
Lecture1 pattern recognition............
.pdf is not working space design for the following data for the following dat...
05. PRACTICAL GUIDE TO MICROSOFT EXCEL.pptx
climate analysis of Dhaka ,Banglades.pptx
STUDY DESIGN details- Lt Col Maksud (21).pptx
1_Introduction to advance data techniques.pptx
Miokarditis (Inflamasi pada Otot Jantung)
Data_Analytics_and_PowerBI_Presentation.pptx
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
MODULE 8 - DISASTER risk PREPAREDNESS.pptx

10. Graph Databases

  • 1. Graph Oriented Databases Ciao ciao Vai a fare ciao ciao Dr. Fabio Fumarola
  • 2. Outline • Introduction • The Lack of relationship for RDBMS and NoSQL • Graph Databases: Features • Relations • Query Language • Data Modeling with Graphs • Conclusions 2
  • 3. Introduction • We live in a connected world • Everything is connected: Social Network, Biology, Bioinformatics • The NoSQL databases analyzed store data using aggregate • Here we compare graph databases with relational databases and aggregate NOSQL in storing graph data 3
  • 4. Three Facts 1. Relational Databases Lack Relationships 1. NoSQL Databases also Lack Relationships 2. Graph Databases Embrace Relationships 4
  • 5. Relational Databases Lack Relationships • For decades we tried to accommodate connected, semi-structured datasets inside relational databases. • But: – relational databases are designed to codify tabular structures – They struggle when modeling ad hoc exceptional relationships that are in real world. 5
  • 6. Relational Databases Lack Relationships • Relationships in relational database only mean joining tables • But we want to model the semantic of relationships that connect real world • As outlier data multiplies: 1. The structure of the dataset becomes more complex and less uniform 2. The relational data becomes more complex and less uniform (large join tables, sparsely populated rows, a lot o null values) 6
  • 7. Example of customer-centric orders • Complex joins • Foreign key constraints • Sparse table with null values • Reciprocal queries are costly “What products did a customer buy?” 7
  • 8. NoSQL Databases Also Lack Relationships • key-value, document, or column-oriented store sets of disconnected documents/values/columns • One well-known strategy for adding relationships is to embed an aggregate’s identifier inside the field belonging to another aggregate • But this require joins at the application level • Some NoSQL have some concept of navigability but it is expensive for complex joins 8
  • 9. Example of aggregate oriented orders • Some properties are references to foreign aggregates • This relationship are not first-class citizens • Are not intended as real realtionships 9
  • 10. Example of a Small Social Network • it’s easy to find a user’s immediate friends • friendship isn’t always reflexive • We can have brute-force scan across the whole dataset looking for friends entries 10
  • 11. Graph Databases Embrace Relationships • The previous examples have dealt with implicitly connected data • We infer semantic dependencies between entities • We model the data based on this connections • Our application have to navigate on this flat and disconnected data, and deal with slow queries. • In contrast, in the graph world, connected data is stored as connected data 11
  • 12. Example Social Network 12 • The node user:Bob is a Vertex with a property Bob • We also see relations which are Edges: • Boss_of • Friend_of • Married_to
  • 15. Consistency • Since Graph DBs operate on connected nodes, they could not scale well distributing nodes across servers. • There are solutions supporting distribution: – Neo4j uses one master and several slaves – OrientDB uses MVCC for distributed eventual data structures – TitanDB partition data by using HBase or Cassandra 15
  • 16. Transactions • Most of the Graph DB are ACID-compliant • Before doing an operation we have to start a transaction. • Without wrapping operations in a transaction we will get an Exception. 16
  • 17. Availability • Neo4j from version 1.8 achieves availability by providing for replicated slaves. • Infinity Graph, FlockDB and TitanDB provides for distribute storage of the nodes. • Neo4J uses Zookeeper to keep track of the last transaction Ids persisted on each slave node and the current master node 17
  • 19. Relations • Relations in a graph naturally forms paths. • Querying or traversing the graph involves following a path. • A query on the graph is also known as traversing the graph • As advantage we can change the traversing requirements without changing nodes and edges 19
  • 20. Relations • In graph databases traversal operation are highly efficient. • In the book Neo4j in Action, Partner and Vukotic perform an experiment comparing relational store and Neo4j 20
  • 21. Relations • In a depth two (friend-of-friend), both relational db and graph db perform well enough • But when we do the depth three it clear that relational db can no longer deal 21
  • 22. Relations • Both aggregate store and relational databases perform poorly because of the index lookups. • Graphs, on the other hand, use index-free adjacency list to ensure that traversing connected data is extremely fast. 22
  • 23. Relations another case study • Let us consider the purchase history of a user as connected data. • If we notice that users who buy strawberry ice cream also buy espresso beans, we can start to recommend those beans to users who normally only buy the ice cream. 23
  • 24. Relations and Recommendations • The previous was a one dimensional recommendation • We can join our graph with graph from other domains. • For example, we can ask to fine – “all the flavors of ice cream liked by people who live near a user, and enjoy espresso, but dislike Brussels sprouts.” 24
  • 25. Relations and Patterns • We can use relations to query graph-patterns • Such pattern-matching queries are: – extremely difficult to write in SQL – And are laborious to write against aggregate stores • In both cases they tend to perform very poorly • In the other hand, graph databases are optimized for such kind of queries 25
  • 27. Query Language • Graph DBs support query languages such as Gremlin, Cypher and SPARQL • Gremlin is a DSL for traversing graphs; • It can traverse all the graph databases implementing the Blueprints 27
  • 28. 1. Indexing: Nodes and Edges • Indexes are necessary to find the starting node to being traversal. • How Indexes works: – Can index properties of nodes and edges. – Adds are done in transactions • Nodes retrieved can be used to raise queries 28
  • 29. 2. Querying In- Out- Relationships • Having a node we can query both for Incoming and Outgoing relationships. • We can apply directional filters on the queries when querying for relations 29
  • 30. 3. Querying Breadth- Depth- • Graph databases are really powerful to query for incoming and outgoing relationships. • Moreover, we can make the traverser go top-down or sideways on the graph by using: – BREADTH_FIRST or – DEPTH_FIRST 30
  • 31. 4. Querying Paths • An other good feature of graph databases is – finding paths between two nodes. – Determining if there are multiple paths – finding the shortest path • Many Graph DBs use algorithms such as the Dijkstra’s algorithm for finding shortest paths. 31
  • 32. 5. Querying Paths • Finally, with Graph DBs it is possible to use Match operator • The MATCH is used for matching patterns in relationships • The WHERE filters the properties on a node or relationship • The RETURN specifies what to get in the result set. 32
  • 33. Data Modeling with Graphs Intro 33
  • 34. Data Modeling with Graphs how do we model the world in graph terms? 34
  • 35. how do we model the world in graph terms? • Formalization of the base model • Enrich the model • Testing the model 35
  • 36. Formalization of the base model • Modeling is an abstracting activity motivated by a particular need or goal • We model in order to define structures that can manipulated. • There are no natural representations of the world the way it “really is,” • There are just many purposeful selections, abstractions, and simplifications that useful for satisfying a particular goal 36
  • 37. Formalization of the base model • Graph data modeling is different from many other techniques. • There is a close affinity between logical and physical models. • In relational databases we start from a logical model to arrive to the physical model. • With graph databases, this gap shrinks considerably. 37
  • 38. The Graph Model • A property graph is made up of nodes, relationships, and properties. 38
  • 39. Publishing Messages • We organize messages in order 39
  • 40. Nodes Nodes contain properties •Think of nodes as documents that store properties in the form of arbitrary key-value pairs. •The keys are strings and the values are arbitrary data types. 40
  • 41. Relationships Relationships connect and structure nodes. •A relationship always has a direction, a label, and a start node and an end node—there are no dangling relationships. •Together, a relationship’s direction and label add semantic clarity to the structuring of nodes. 41
  • 42. Relationships: Attributes Like nodes, relationships can also have properties. •The ability to add properties to relationships is particularly useful for: – Providing additional metadata for graph algorithms – Adding additional semantics to relationships (including quality and weight), – and for constraining queries at runtime. 42
  • 43. Modeling Steps: Outline • The initial stage of modeling is similar to the first stage of many other data modeling techniques, that is: – to understand and agree on the entities in the domain – how they interrelate – and the rules that govern their state transitions 43
  • 44. Describe the Model in Terms of the Application’s Needs • Agile user stories provide a concise means for expressing an outside-in, user-centered view of the application needs. • Here’s an example of a user story for a book review web application: – AS A reader who likes a book, – I WANT to know which books other readers who like the same book have liked, – SO THAT I can find other books to read. 44
  • 45. Describe the Model in Terms of the Application’s Needs • This story expresses a user need, which motivates the shape and content of our data model. • From a data modeling point of view: – the AS A clause establishes a context comprising two entities—a reader and a book—plus the LIKES relationship that connects them. – The I WANT clause exposes more LIKES relationships, and more entities: other readers and other books. 45
  • 46. Describe the Model in Terms of the Application’s Needs • The entities and relationships in analyzing the user story quickly translate into a simple data model 46
  • 47. Modeling Rationale • Use nodes to represent entities • Use relationships both: – to express the connections between entities and – to establish semantic context for each entity • Use relationship direction to further clarify relationship semantics 47
  • 48. Describe the Model: Guidelines • Use node properties – to represent entity attributes, plus any necessary entity metadata, such as timestamps, version numbers, etc • Use relationship properties – to express the strength, weight, or quality of a relationship, plus any necessary relationship metadata, such as timestamps, version numbers, etc. 48
  • 49. Modeling Temporal Relations as Nodes • When two or more domain entities interact for a period of time, a fact emerges • We represent these facts as separate nodes • In the following examples we show how we might model facts and actions using intermediate nodes. 49
  • 50. Example: Employment Ian was employed as an engineer at Neo Technology 50
  • 51. Example: Performance William Hartnell played the Doctor in the story The Sensorites 51
  • 52. Example: Emailing Ian emailed Jim, and copied in Alistair 52
  • 53. Example: Timeline Tree 53 A timeline tree showing the broadcast dates for four episodes of a TV program
  • 54. Example: Linked-List A doubly linked list representing a time-ordered series of events 54
  • 55. Iterative and Incremental • We develop the data model feature by feature, user story by user story • This will ensure we identify the relationships our application will use to query the graph • With the iterative and incremental delivery of application features we will be a corrected model that provides the right abstraction 55
  • 56. Data Modeling: Enrich • The next steps diverges from the relational data methodology • Instead of transforming a domain model’s graph-like representation into tables, we enrich it. • That is, for each entity in our domain, “we ensure that we’ve captured both the properties and the connections to neighboring entities necessary to support our application goals”. 56
  • 57. Data Modeling: Enrich • Remember, the domain model is not totally aligned to reality. • it is a purposeful abstraction of those aspects of our domain relevant to our application goals. • By enriching our domain graph with additional properties and relationships, we effectively produce a graph model aligned to our application’s data needs 57
  • 58. Data Modeling: Enrich In graph terms, we are ensuring that: •each node has the appropriate properties •every node is in the correct semantic context. we do this by creating named and directed (and often attributed) relationships between the nodes to capture the structural aspects of the domain. 58
  • 59. Data Modeling: Test • The next step is to test how suitable it is for answering realistic queries • Also if Graph DB are great in supporting evolving structures there are some design decisions to consider • By reviewing the domain model and the resulting graph model at this early stage, we can avoid these pitfalls. 59
  • 60. Data Modeling: Test • In practice there are two techniques that we can apply here • The first, and simplest, is just to check that the graph reads well. • We pick a start node, and then follow relationships to other nodes, reading each node’s role and each relationship’s name as we go • Doing so should create sensible sentences 60
  • 61. Data Modeling: Test • The second one is to consider queries we’ll run on the graph. • To validate that the graph supports the kinds of queries we expect to run on it, we must describe those queries. • Given a described query if we can easily write the query in Cypher or Gremlin we can be more certain that the graph meets the needs of our domain. 61
  • 63. Avoid Anti-Patterns • In the general case, don’t encode entities into relationships. • It’s also important to realize that graphs are a naturally additive structure • It’s quite natural to add facts in terms of domain entities and how they interrelate adding nodes and relationships • If we model in accordance with the questions we want to ask of our data, an accurate representation of the domain will emerge. 63
  • 64. When to Use • Connected Data • Routing, Dispatch, and Location-based Services • Recommendation Engines 64
  • 65. When Not to Use • When you need to update all or a subset of entities, for example in analytics • In situation when you need to apply operations that work on the global graph • When you don’t know the starting point of your query 65

Editor's Notes

  • #24: For example, users often want to see their order history, so we’ve added a linked list structure to the graph that allows us to find a user’s most recent order by following an outgoing MOST_RECENT relationship. We can then iterate through the list, going further back in time, by following each PREVIOUS relationship. If we want to move forward in time, we can follow each PREVIOUS relationship in the opposite direction, or add a reciprocal NEXT relationship.