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

PDF
Relationship Counselling with Neo4j
PDF
PDF
23 data-structures
PDF
PDF
The Panama Papers: analysing it with neo4j and neo4j spatial - MINC 2016
PDF
GraphConnect Europe 2016 - Securely Deploying Neo4j into AWS - Benjamin Nussbaum
PPTX
Megan Heaton interior Design Portfolio
PDF
A McGee Flournoy Interior Design Portfolio 2014
Relationship Counselling with Neo4j
23 data-structures
The Panama Papers: analysing it with neo4j and neo4j spatial - MINC 2016
GraphConnect Europe 2016 - Securely Deploying Neo4j into AWS - Benjamin Nussbaum
Megan Heaton interior Design Portfolio
A McGee Flournoy Interior Design Portfolio 2014

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

PDF
Introduction to Graph Databases with Neo4J
PDF
Introduction to graph databases, Neo4j and Spring Data - English 2015 Edition
PDF
Introduction to Graph Databases wth neo4J
PPT
Hands on Training – Graph Database with Neo4j
PDF
There and Back Again, A Developer's Tale
PPTX
Introduction to graph databases in term of neo4j
PDF
Graph Databases, a little connected tour (Codemotion Rome)
PDF
Graph Database, a little connected tour - Castano
PPTX
Graphs fun vjug2
PDF
3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DB
PDF
Intro to Neo4j 2.0
PDF
Lab3-DB_Neo4j
PPTX
Neo4j 20 minutes introduction
PDF
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
PPT
Processing Large Graphs
PDF
Neo4j Data Science Presentation
PDF
Introduction to Neo4j - a hands-on crash course
PDF
Graph Database Using Neo4J
PDF
03 introduction to graph databases
Introduction to Graph Databases with Neo4J
Introduction to graph databases, Neo4j and Spring Data - English 2015 Edition
Introduction to Graph Databases wth neo4J
Hands on Training – Graph Database with Neo4j
There and Back Again, A Developer's Tale
Introduction to graph databases in term of neo4j
Graph Databases, a little connected tour (Codemotion Rome)
Graph Database, a little connected tour - Castano
Graphs fun vjug2
3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DB
Intro to Neo4j 2.0
Lab3-DB_Neo4j
Neo4j 20 minutes introduction
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Processing Large Graphs
Neo4j Data Science Presentation
Introduction to Neo4j - a hands-on crash course
Graph Database Using Neo4J
03 introduction to graph databases

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation theory and applications.pdf
PDF
Machine learning based COVID-19 study performance prediction
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Spectroscopy.pptx food analysis technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Machine Learning_overview_presentation.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation theory and applications.pdf
Machine learning based COVID-19 study performance prediction
The AUB Centre for AI in Media Proposal.docx
Spectroscopy.pptx food analysis technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Unlocking AI with Model Context Protocol (MCP)
Spectral efficient network and resource selection model in 5G networks
Machine Learning_overview_presentation.pptx
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Electronic commerce courselecture one. Pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Review of recent advances in non-invasive hemoglobin estimation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Assigned Numbers - 2025 - Bluetooth® Document
20250228 LYD VKU AI Blended-Learning.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm

Use Neo4j In Your Next Java Project