This document discusses using Neo4j graph databases for projects instead of traditional SQL databases. It notes that graph databases better model complex relationships, scale to large amounts of data more efficiently, and allow for faster querying of connected data through graph traversal compared to SQL databases which require complex joins. Examples are provided showing how queries involving friends of friends or finding connection paths between characters can be done more simply and quickly using the Cypher query language in Neo4j compared to equivalent SQL queries. A demo is also promised to illustrate these benefits hands-on.
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Use Neo4j In Your Next Java Project
1. Use Neo4j In Your
Next Java Project
Love relationships again
Tobias Coetzee
@tobiascode
2. 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
3. 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
5. Queries with lots of joins to get to the final answer
Similar Data Models
Configuration
Security
Navigation
6. 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
7. Graph Databases
Nodes
Represent the entities or
records in the database
Relationships
Link nodes together
Properties
Nodes and relationships can
also have properties
17. 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
18. 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
30. 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
33. 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