NOSQL MICRO PROJECT
Neo4j and Graph Databases
Suvagiya Sahil - 216400307038
Sumaniya Amit - 216400307010
A Graph Is Connected Data
TRAFFIC
LIGHTS
ROAD
A Graph Is Connected Data
A Graph Is Connected Data
Use of Graphs has created some of the most successful companies in the world
C
B 34,3%
A 38,4%
3,3%
F
3,9%
D
3,8%
E
8,1%
1,8%
1,8% 1,8%
1,8%
1,8%
NEO4j USE CASES GRAPH THINKING:
Real Time Recommendations
Real Time Recommendations
Master Data Management
Fraud Detection
HT
UG
Graph Based Search
GHT
BO
BOUGHT
HT
BOU
VIEWE
VIE
UG
WE
ED
BO
Network & IT-Operations
VIEW
D
BO
UG
HT
Identity & Access Management
NEO4j USE CASES
Real Time Recommendations
Master Data Management
Fraud Detection
Graph Based Search
Network & IT-Operations
Identity & Access Management
“As the current market leader in graph databases,
and with enterprise features for scalability and
availability, Neo4j is the right choice to meet our
demands.” Marcos Wada
Software Developer, Walmart
NEO4j USE CASES GRAPH THINKING:
Master Data Management
Real Time Recommendations
S
LEAD
Master Data Management
MANAGES
Fraud Detection LEA
ES
D
RE
S
AG
GI
AN
ON
Graph Based Search
ES
Network & IT-Operations
RAT
MA
BO
LLA
NA
Identity & Access Management
GE
CO
ION
S
E G
R
MANA
GES
S
LEAD
NEO4j USE CASES GRAPH THINKING:
Fraud Detection
Real Time Recommendations
T
COUN
Master Data Management
D_AC
Fraud Detection
E
D IS
OPEN
HA
E _ IS
U
S
SS SU
_ I ED
Graph Based Search IS
Network & IT-Operations
T
UN
S
Identity & Access Management
E
O
V
LI
LI
CC
VE
_A
HAS
ED
N
PE
O
NEO4j USE CASES GRAPH THINKING:
Graph Based Search
Real Time Recommendations IN
SOUR
Master Data Management
CE
IN
Fraud Detection UR
CE
SOU
RCE
S O
Graph Based Search
E
UR
PT
CA
IN
Network & IT-Operations
US
ES
US
ES
Identity & Access Management CREATE IN
USE
PU S
BL
IS
H
CLUDE
IN
INCLUDE
NEO4j USE CASES GRAPH THINKING:
Network & IT-Operations
Real Time Recommendations
BRIDGES
Master Data Management
Fraud Detection S
TE
CTS
U
RO
RO
SR
NNE
UT
Graph Based Search
WE
ES
CO
PO
Network & IT-Operations POWE
RS
POWERS
Identity & Access Management
QU
ER
BR
IES
OW
SE
S OSTS
H
NEO4j USE CASES GRAPH THINKING:
Identity And Access Management
Real Time Recommendations
TRUST
S
Master Data Management
Fraud Detection
TRUSTS
O
W
NS
Graph Based Search
CAN_READ
S
ID
TE
AUTH
ICA
OW
NT
Network & IT-Operations
ENTI
NS
ID
E
TH
CATE
AU
Identity & Access Management
S
A way of representing data
Relational Database
raw data
A way of representing data
Graph
Relational Database Database
Good for: Good for:
• Well-understood data structures that • Dynamic systems: where the data
don’t change too frequently topology is difficult to predict
• Known problems involving discrete parts • Dynamic requirements:
of the data, or minimal connectivity the evolve with the business
• Problems where the relationships in
data contribute meaning & value
THE PROPERTY GRAPH
DATA MODEL
Property Graph Model Components
name: “Dan”
Nodes born: May 29, 1970 name: “Ann”
• The objects in the graph twitter: “@dan” born: Dec 5, 1975
• Can have name-value properties LOVES
• Can be labeled
LOVES
Relationships PERSON PERSON
• Relate nodes by type and LIVES WITH
direction
• Can have name-value properties DR
NS
IV
ES
OW
since:
Jan 10, 2011
brand: “Volvo”
CAR model: “V70”
WHY GRAPHS?
Intuitivness
Speed
Agility
Intuitivness
Relational Versus Graph Models
Relational Model Graph Model
ANDREAS
DELIA
TOBIAS
MICA
OWS
KN
TOBIAS KNOWS
ANDREAS MICA
KNO
Person WS
Person-Friend Friend
DELIA
Index free adjacency
Speed
“We found Neo4j to be literally thousands of times faster
than our prior MySQL solution, with queries that require
10-100 times less code. Today, Neo4j provides eBay with
functionality that was previously impossible.”
- Volker Pacher, Senior Developer
“Minutes to milliseconds” performance
Queries up to 1000x faster than RDBMS or other NoSQL
Agility =
A Naturally Adaptive Model
+
A Query Language Designed
for Connectedness
CYPHER
SQL for graphs
Representing Bi-Directionality
FB_FRIENDS
MATCH (:Person { name:“Ann”} ) - [:FB_FRIENDS] - > (:Person { name:“Dan”} )
MATCH (:Person { name:“Ann”} ) - [:FB_FRIENDS] - (:Person { name:“Dan”} )
Cypher
Typical Complex SQL Join The Same Query using Cypher
MATCH (boss)-[:MANAGES*0..3]->(sub),
(sub)-[:MANAGES*1..3]->(report)
WHERE boss.name = “John Doe”
RETURN sub.name AS Subordinate,
count(report) AS Total
Project Impact
Less time writing queries
• More time understanding the answers
• Leaving time to ask the next question
Less time debugging queries:
• More time writing the next piece of code
• Improved quality of overall code base
Code that’s easier to read:
• Faster ramp-up for new project members
• Improved maintainability & troubleshooting
Neo4j
Graph Database
• Property graph data model
• Nodes and relationships
• Native graph processing
• (open)Cypher query language
neo4j.com
Neo4j – Key Product Features
Powerful, Expressive Query Language
Native Graph Storage Requires 10x to 100x less code than SQL
Ensures data consistency and
Scalability and High Availability
performance
Vertical and horizontal scaling optimized
Native Graph Processing for graphs
Millions of hops per second, in real time
Built-in ETL
“Whiteboard Friendly” Data Modeling Seamless import from other databases
Model data as it naturally occurs
Integration
High Data Integrity Drivers and APIs for popular languages
Fully ACID transactions
MATCH
(A)
Attributed JOIN Tables -> Relationships with Properties
As a Graph
using openCypher
Property Graph Model
REPORTS_TO
Steven Andrew
NODE NODE
CREATE (:Employee{ firstName:“Steven”} ) -[:REPORTS_TO]-> (:Employee{ firstName:“Andrew”} )
LABEL PROPERTY LABEL PROPERTY
Who do people report to?
MATCH
(e:Employee)<-[:REPORTS_TO]-(sub:Employee)
RETURN
*
Who do people report to?
Who do people report to?
MATCH
(e:Employee)<-[:REPORTS_TO]-(sub:Employee)
RETURN
e.employeeID AS managerID,
e.firstName AS managerName,
sub.employeeID AS employeeID,
sub.firstName AS employeeName;
Who do people report to?
Who does Robert report to?
MATCH
p=(e:Employee)<-[:REPORTS_TO]-(sub:Employee)
WHERE
sub.firstName = ‘Robert’
RETURN
p
What is Robert’s reporting chain?
MATCH
p=(e:Employee)<-[:REPORTS_TO*]-(sub:Employee)
WHERE
sub.firstName = ‘Robert’
RETURN
p
What is Robert’s reporting chain?
Who’s the Big Boss?
MATCH
(e:Employee)
WHERE
NOT (e)-[:REPORTS_TO]->()
RETURN
e.firstName as bigBoss
Who’s the Big Boss?
Product Cross-Selling
MATCH
(choc:Product {productName: 'Chocolade'})
<-[:INCLUDES]-(:Order)<-[:SOLD]-(employee),
(employee)-[:SOLD]->(o2)-[:INCLUDES]->(other:Product)
RETURN
employee.firstName,
other.productName,
COUNT(DISTINCT o2) as count
ORDER BY
count DESC
LIMIT 5;
Product Cross-Selling