SlideShare a Scribd company logo
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

More Related Content

Similar to Use Neo4j In Your Next Java Project

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.
Radu-Sebastian Amarie
 
Neo4j 20 minutes introduction
Neo4j 20 minutes introductionNeo4j 20 minutes introduction
Neo4j 20 minutes introduction
András Fehér
 
Applied Redis
Applied RedisApplied Redis
Applied Redis
hotrannam
 
Thinking about graphs
Thinking about graphsThinking about graphs
Thinking about graphs
Neo4j
 
Neo4j Presentation
Neo4j PresentationNeo4j Presentation
Neo4j Presentation
Max De Marzi
 
Awesome Tools 2017
Awesome Tools 2017Awesome Tools 2017
Awesome Tools 2017
Noel De Martin Fernandez
 
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?
DATAVERSITY
 
Neo4j Data Science Presentation
Neo4j Data Science PresentationNeo4j Data Science Presentation
Neo4j Data Science Presentation
Max De Marzi
 
Redis Day TLV 2018 - Graph Distribution
Redis Day TLV 2018 - Graph DistributionRedis Day TLV 2018 - Graph Distribution
Redis Day TLV 2018 - Graph Distribution
Redis Labs
 
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
 
Data Modeling with Neo4j
Data Modeling with Neo4jData Modeling with Neo4j
Data Modeling with Neo4j
Neo4j
 
Introducción a Neo4j
Introducción a Neo4jIntroducción a Neo4j
Introducción a Neo4j
Neo4j
 
Database Theory
Database TheoryDatabase Theory
Database Theory
Lambert Lum
 
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
ijwscjournal
 
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
ijwscjournal
 
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
ijwscjournal
 
Logical ERD 2022.pptx
Logical ERD  2022.pptxLogical ERD  2022.pptx
Logical ERD 2022.pptx
Jeff Jacobs
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
Eric Bottard
 
Graph and RDF databases
Graph and RDF databasesGraph and RDF databases
Graph and RDF databases
Nassim Bahri
 
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
Alex Miller
 

Similar to 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
 
Thinking about graphs
Thinking about graphsThinking about graphs
Thinking about graphs
 
Neo4j Presentation
Neo4j PresentationNeo4j Presentation
Neo4j Presentation
 
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
 

Recently uploaded

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 

Recently uploaded (20)

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 

Use Neo4j In Your Next Java Project