Slide 1

Slide 1 text

Jennifer Reif Email: [email protected] Twitter: @JMHReif LinkedIn: linked.com/in/jmhreif Github: github.com/JMHReif Website: jmhreif.com Graph Databases Solving Problems with Connected Data

Slide 2

Slide 2 text

Who Am I? • Developer + Advocate • Continuous learner • Blogger • Speaker • Other: geek Jennifer Reif Email: [email protected] Twitter: @JMHReif LinkedIn: linked.com/in/jmhreif Github: github.com/JMHReif Website: jmhreif.com

Slide 3

Slide 3 text

It’s all about data Everything is built on data • Businesses, industry, governments, economics, people • Our understanding of the world • Data is how we learn • Trial and error • Asking questions • Accumulated over time

Slide 4

Slide 4 text

Domain-Driven Design (DDD) • Mutual understanding of domain, concepts • Iterations • Understanding data = better understanding of result • Better product, minimum functionality • Sanity check code

Slide 5

Slide 5 text

Databases - another one?!

Slide 6

Slide 6 text

Relational database • Pros: • Slices of data that can be easily assembled with queries • Handles data integrity and unique rows, low data duplication • Cons: • All relationships must be assembled with JOINs (with NF adherence) • JOINs are constructed from human knowledge Goal: Assemble data into meaningful sets

Slide 7

Slide 7 text

Entity-Relationship Diagram

Slide 8

Slide 8 text

NoSQL/Document database • Pros: • Can handle varied (unstructured) data more readily • Groups related info in a single place • Cons: • Designed to avoid JOINs and SQL • Makes aggregation operations cumbersome Goal: Group related info together

Slide 9

Slide 9 text

NoSQL/Document Schema

Slide 10

Slide 10 text

Graph database Goal: Best of both worlds • Pros: • Relationships stored with related entities, no assembly required • Make JOIN operations easy, visual even • Cons: • Storing relationships requires some write operation overhead • Di ff erent mentality for modeling, querying, etc

Slide 11

Slide 11 text

Graph databases

Slide 12

Slide 12 text

Have to pick just one? • Polyglot persistence: • Using multiple persistence strategies, each serving a di ff erent need • “Using the right tool for the job”

Slide 13

Slide 13 text

What is a graph?

Slide 14

Slide 14 text

Graph History Leonard Euler Seven Bridges of Konigsberg problem. Leonhard Euler, 1735

Slide 15

Slide 15 text

Graph databases 2010 New tech arises from… • Solution need • Missing solution in the technology space • Looking for a “better way” to handle certain problems

Slide 16

Slide 16 text

What Does It Solve? Product use case • Document path (not just data) • Answering how and why • Understanding connections • Find alternates, impacts, etc. • Produce better assumptions, decisions

Slide 17

Slide 17 text

Graphs add context and meaning Not just point-to-point, but HOW they connect

Slide 18

Slide 18 text

Misconceptions “Gotchas” • Database - physical storage of data • Not just analysis tool • Not just visualization • Can be “system of record” / “source of truth” db • Not just analytics workloads, transactional too • Not a silver bullet (like any technology) • There are things it does NOT do well

Slide 19

Slide 19 text

Graph Structure

Slide 20

Slide 20 text

Whiteboard Friendliness Easy to design and model direct representation of the data

Slide 21

Slide 21 text

Data model drawn = real-world data model

Slide 22

Slide 22 text

Data model drawn = data stored in graph

Slide 23

Slide 23 text

Graph components • Node (vertex) • Relationship (edge)

Slide 24

Slide 24 text

Nodes Graph Components • Represent objects or entities • Can be labeled Order Product

Slide 25

Slide 25 text

Nodes Graph components • Represent objects or entities • Can be labeled • May have properties Order Product Employee orderId: 162468 total: $8320.48 productId: 08746589 name: “Ipoh Coffee” id: 247924 startDate: 2016-05-04 role: “Salesperson”

Slide 26

Slide 26 text

Relationships Graph components • Must have a type • Must have a direction Order Product Employee orderId: 162468

Slide 27

Slide 27 text

Relationships Graph components • Must have a type • Must have a direction • May have properties Order Product Employee orderId: 162468 commission: .02

Slide 28

Slide 28 text

Relationships Graph components • Must have a type • Must have a direction • May have properties • Nodes can share multiple relationships Order Product Employee orderId: 162468

Slide 29

Slide 29 text

Label Graph Components • A group of nodes • Like a category Person

Slide 30

Slide 30 text

Label Graph Components • A group of nodes • Like a category Person Employee Customer

Slide 31

Slide 31 text

Property Graph components • Key-value pair • Associated with node or relationship • Like a variable name and value Order Employee orderId: 162468 id: 247924 SOLD total: $8320.48 date: 2022-08-16 commission: .02 startDate: 2016-05-04 role: “Salesperson”

Slide 32

Slide 32 text

Query Language

Slide 33

Slide 33 text

SQL vs Cypher SELECT o.OrderId, o.Total, o.Items, op.Quantity, op.Price, p.Name FROM Order o LEFT JOIN OrderedProduct op ON op.OrderId = o.OrderId LEFT JOIN Product p ON op.ProductId = p.ProductId; SQL Cypher MATCH (o:Order)-[r:CONTAINS]->(p:Product) RETURN o, r, p; Order Product OrderedProduct Order Product

Slide 34

Slide 34 text

Cypher • Functional and visual • Based on ASCII-art • Declarative query language • Focuses on what to retrieve • Not how A B LIKES MATCH (A)-[:LIKES]->(B)

Slide 35

Slide 35 text

Cypher: powerful and expressive Jennifer Neo4j WORKS_FOR CREATE (:Person { name: ‘Jennifer’}) -[:WORKS_FOR]-> (:Company { name: ‘Neo4j’}) NODE PROPERTY NODE PROPERTY LABEL LABEL

Slide 36

Slide 36 text

Cypher: read Jennifer Neo4j WORKS_FOR MATCH (:Person { name: ‘Jennifer’} ) -[:WORKS_FOR]-> ( whom ) 
 RETURN whom

Slide 37

Slide 37 text

Cypher in 20 seconds… • Nodes look like this: • (var:Label) OR (var:Label {propKey: propValue}) • Relationships look like this: • -[var:REL_TYPE]-> OR -[var:REL_TYPE {propKey: propValue}]-> • Using Cypher is looking for patterns of those nodes/rels: • (var1:Label)-[var2:REL_TYPE]->(var3:Label)

Slide 38

Slide 38 text

Building Applications

Slide 39

Slide 39 text

Building applications • Drivers: lots of languages supported • Plugins/extensions/libraries: • APOC utilities • Graph Data Science • GraphQL • …and more! • Integrations/frameworks: • Spring, Micronaut, Quarkus • Kettle, Spark, PowerBI, JDBC, etc.

Slide 40

Slide 40 text

Demo!

Slide 41

Slide 41 text

Resources • Neo4j AuraDB Free: dev.neo4j.com/aura-java • Neo4j GraphAcademy: dev.neo4j.com/learn • Neo4j blog: dev.neo4j.com/blog • Neo4j YouTube: dev.neo4j.com/videos Jennifer Reif Email: [email protected] Twitter: @JMHReif LinkedIn: linked.com/in/jmhreif Github: github.com/JMHReif Website: jmhreif.com