SlideShare una empresa de Scribd logo
1 de 34
Descargar para leer sin conexión
Use Neo4j In Your
Next Java Project
Love relationships again
Tobias Coetzee
@tobiascode
All Roads Lead To SQL
Do we even have
other choices?
Every project we work on will have
some form of database, 99% of
those in the enterprise will be a
relational database
Impedance Mismatch
The database model does not
match the domain model
Not Scaling
More data means less speed
Complex Queries
Lots of joins and some self
joining nightmares as a bonus
Relationship Problems
Facebook For Superheroes
MEMBER_OF
TOOK_PART_IN
WAS_IN
Characters
Events
Teams
Stories
CONSISTS_OF
FRIEND_OF
Queries with lots of joins to get to the final answer
Similar Data Models
Configuration
Security
Navigation
Graph Databases
Just Mathematics
Based on graph theory, created
by Leonhard Euler
All About Relationships
In graph databases relationships
are first class citizens
Neo4j
Most well known and widely
used graph database
Graph Databases
Nodes
Represent the entities or
records in the database
Relationships
Link nodes together
Properties
Nodes and relationships can
also have properties
MEMBER_OF
MEMBER_OF
FRIEND_OF
WAS_IN
TOOK_PART_IN • Eyes: Blue
• Hair: None
• Citizenship: Canada• Since: 14 Feb 2001
Graph Databases
The database model does not
match the domain model
Impedance Mismatch
Impedance Mismatch
Character_Team
Character_Event
Team_Event
Character_Story
Team_Story
Event_Story
Friends
MarvelCharacter
Team
Event
Story
Traditional Solutions
ORM Frameworks, e.g.
Hibernate or Spring Data
Boilerplate code generation
tools
Impedance Mismatch
Impedance Mismatch
MEMBER_OF
TOOK_PART_IN
WAS_IN
Characters
Events
Teams
Stories
CONSISTS_OF
FRIEND_OF
MATCH
(c:Character)-[:MEMBER_OF]->(t:Team)
WHERE t.name = 'Avengers'
RETURN c.name
Cypher Intro
Demo Time
Lots of joins and some self
joining nightmares as a bonus
Complex Queries
Denormalise the database
Hide complexity behind
views and stored procedures
Traditional Solutions
Complex Queries
Friends of Friends
Name Number Friends
in Common
Vision 51
Wolfsbane 38
Punisher 33
Rage 38
Shard 25
Wind Dancer 25
Possible friend recommendations for Deadpool
SELECT FriendOfFriend.Name, COUNT(*)
FROM MarvelCharacter deadpool
INNER JOIN Friends DeadpoolFriends
ON deadpool.Id = DeadpoolFriends.CharacterId1
INNER JOIN Friends FriendsFriends
ON DeadpoolFriends.CharacterId2 = FriendsFriends.CharacterId1
INNER JOIN MarvelCharacter FriendOfFriend
ON FriendsFriends.CharacterId2 = FriendOfFriend.Id
WHERE deadpool.Name = 'Deadpool'
AND FriendsFriends.CharacterId2 NOT IN( SELECT CharacterId2
FROM MarvelCharacter
INNER JOIN Friends
ON MarvelCharacter.Id = CharacterId1
WHERE Name = 'Deadpool')
GROUP BY FriendOfFriend.Name
ORDER BY COUNT(*) DESC
Sooo Many Joins
MATCH (deadpool:Character)-[:FRIEND_OF*2]->(FriendOfFriend)
WHERE deadpool.name = 'Deadpool'
AND NOT (deadpool)-[:FRIEND_OF]->(FriendOfFriend)
AND NOT deadpool = FriendOfFriend
RETURN FriendOfFriend.name, COUNT(*)
ORDER BY COUNT(*) DESC, FriendOfFriend.name
Sooo Many Joins
MATCH (deadpool:Character)-[:FRIEND_OF*2]->(FriendOfFriend)
Sooo Many Joins
FROM MarvelCharacter deadpool
INNER JOIN Friends DeadpoolFriends
ON deadpool.Id = DeadpoolFriends.CharacterId1
INNER JOIN Friends FriendsFriends
ON DeadpoolFriends.CharacterId2 = FriendsFriends.CharacterId1
INNER JOIN MarvelCharacter FriendOfFriend
ON FriendsFriends.CharacterId2 = FriendOfFriend.Id
Quick Demo
How Do You Know Him?
MEMBER_OF
MEMBER_OF
FRIEND_OF
How can Deadpool connect to Ironman?
MATCH (deadpool:Character { name:"Deadpool" }),
(other:Character { name:"Ultron" }),
path = shortestPath((deadpool)-[*]-(other))
RETURN path
Shortest Path
MATCH (deadpool:Character { name:"Deadpool" }),
(other:Character { name:"Ultron" }),
path = shortestPath((deadpool)-[*]-(other))
RETURN path
Shortest Path
MATCH (deadpool:Character { name:"Deadpool" }),
(other:Character { name:"Ultron" }),
path = shortestPath((deadpool)-[*]-(other))
RETURN path
Shortest Path
MATCH (deadpool:Character { name:"Deadpool" }),
(other:Character { name:"Ultron" }),
path = shortestPath((deadpool)-[*]-(other))
RETURN path
Shortest Path
Quick Demo
Not Scaling
More data means less speed
Traditional Solutions
Offline databases
Batch runs to
process data
More indexes
Not Scaling
Speed
Embedded Server
Processing requires reading the
same data you wrote
Fixed Size Records
All records of the same type
have the same size on disk
Index-Free Adjacency
Pointer to the next node
Demo Time
Wrong Usage
This is not a hammer
Wrong Usage
Set Orientated
Lists of things with few or no
joins
Global Operations
Made for local graph
operations
Aggregate Queries
Processing requires reading the
same data you wrote
Thank You
For Staying Till The End!
@tobiascode

Más contenido relacionado

Similar a Use Neo4j In Your Next Java Project

Applied Redis
Applied RedisApplied Redis
Applied Redis
hotrannam
 
NoSQL Search Roadshow Zurich 2013 - Polyglot persistence with no sql
NoSQL Search Roadshow Zurich 2013 - Polyglot persistence with no sqlNoSQL Search Roadshow Zurich 2013 - Polyglot persistence with no sql
NoSQL Search Roadshow Zurich 2013 - Polyglot persistence with no sql
Michael Lehmann
 

Similar a Use Neo4j In Your Next Java Project (20)

Still using MySQL? Maybe you should reconsider.
Still using MySQL? Maybe you should reconsider.Still using MySQL? Maybe you should reconsider.
Still using MySQL? Maybe you should reconsider.
 
Neo4j 20 minutes introduction
Neo4j 20 minutes introductionNeo4j 20 minutes introduction
Neo4j 20 minutes introduction
 
Applied Redis
Applied RedisApplied Redis
Applied Redis
 
Neo4j Presentation
Neo4j PresentationNeo4j Presentation
Neo4j Presentation
 
Thinking about graphs
Thinking about graphsThinking about graphs
Thinking about graphs
 
Awesome Tools 2017
Awesome Tools 2017Awesome Tools 2017
Awesome Tools 2017
 
Graph Databases - Where Do We Do the Modeling Part?
Graph Databases - Where Do We Do the Modeling Part?Graph Databases - Where Do We Do the Modeling Part?
Graph Databases - Where Do We Do the Modeling Part?
 
Neo4j Data Science Presentation
Neo4j Data Science PresentationNeo4j Data Science Presentation
Neo4j Data Science Presentation
 
Redis Day TLV 2018 - Graph Distribution
Redis Day TLV 2018 - Graph DistributionRedis Day TLV 2018 - Graph Distribution
Redis Day TLV 2018 - Graph Distribution
 
NoSQL Search Roadshow Zurich 2013 - Polyglot persistence with no sql
NoSQL Search Roadshow Zurich 2013 - Polyglot persistence with no sqlNoSQL Search Roadshow Zurich 2013 - Polyglot persistence with no sql
NoSQL Search Roadshow Zurich 2013 - Polyglot persistence with no sql
 
Data Modeling with Neo4j
Data Modeling with Neo4jData Modeling with Neo4j
Data Modeling with Neo4j
 
Introducción a Neo4j
Introducción a Neo4jIntroducción a Neo4j
Introducción a Neo4j
 
Database Theory
Database TheoryDatabase Theory
Database Theory
 
SCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASES
SCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASESSCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASES
SCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASES
 
SCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASES
SCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASESSCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASES
SCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASES
 
SCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASES
SCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASESSCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASES
SCHEMA BASED STORAGE OF XML DOCUMENTS IN RELATIONAL DATABASES
 
Logical ERD 2022.pptx
Logical ERD  2022.pptxLogical ERD  2022.pptx
Logical ERD 2022.pptx
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
 
Graph and RDF databases
Graph and RDF databasesGraph and RDF databases
Graph and RDF databases
 
Stream Execution with Clojure and Fork/join
Stream Execution with Clojure and Fork/joinStream Execution with Clojure and Fork/join
Stream Execution with Clojure and Fork/join
 

Último

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Use Neo4j In Your Next Java Project