Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cliff Notes: What Java Developers Need to Know About Graph Databases

Cliff Notes: What Java Developers Need to Know About Graph Databases

Keeping up with database trends? Or learning for a project requirement? Or something else? In this session, we will hit the high points on graph databases and get Java developers what they need to get started quickly and successfully. From data model to applications, these are the Cliff Notes!

10f2b035856eef2b59c02267e3ee9e63?s=128

Jennifer Reif

May 11, 2022
Tweet

More Decks by Jennifer Reif

Other Decks in Technology

Transcript

  1. Cliff Notes: What Java Developers Need to Know About Graph

    Databases Jennifer Reif Email: jennifer.reif@neo4j.com Twitter: @JMHReif Website: jmhreif.com
  2. Who Am I? - Jennifer • Developer + Advocate •

    Continuous learner • Conference speaker • Blogger • Geek Jennifer Reif Email: jennifer.reif@neo4j.com Twitter: @JMHReif Website: jmhreif.com
  3. It’s all about data • Applications are built on data

    • Ever had project where only features explained, not data? • How did it go? • Was product off of expectations?
  4. Alternative: Domain-Driven Design (DDD) • Mutual understanding of domain, concepts

    • Iterations • Understanding data = better understanding of result • Better product, minimum functionality • Sanity check code
  5. Simple or grand foundation?

  6. Data storage

  7. Databases • Database: a structured set of data held in

    a computer, especially one that is accessible in various ways • Relational? NoSQL? Other?
  8. Relational Database (RDBMS) • Oracle: 1979

  9. Relational Database • No data model limitations • Memory-efficient for

    both read and write • CPU-intensive • Difficult query language
  10. Document Database • MongoDB: 2007 "customer" : { "id": "123",

    "firstName" : "Jane", "lastName" : "Doe", "DOB" : "03/12/1989", "department" : "Engineering", "phoneNumbers" : { { "type" : "office", "number" : "650-123-4567" } { "type" : "cell", "number" : "650-321-7654" } } "title" : "Director of QA" }
  11. Document Database • Easy to query (No SQL) • Easy

    horizontal scalability • Little flexibility (relationships pre-baked in document) "customer" : { "id": "123", "firstName" : "Jane", "lastName" : "Doe", "DOB" : "03/12/1989", "department" : "Engineering", "phoneNumbers" : { { "type" : "office", "number" : "650-123-4567" } { "type" : "cell", "number" : "650-321-7654" } } "title" : "Director of QA" }
  12. Graph Database • Neo4j: 2007

  13. Graph Database • No CPU vs Memory/Storage tradeoff (as in

    relational dbs) • No benefit in non-relational data sets • Still a query language
  14. Have to pick just one? • Polyglot persistence: using multiple

    persistence strategies, each serving a different need • “Using the right tool for the job”
  15. Java Application Data Store Options • Relational • Straight JDBC

    • JDBC Template • JOOQ • JPA or Hibernate • NoSQL - Document • MongoDB • Graph • Neo4j
  16. What is a graph?

  17. What is a graph? • Much older than tech of

    the last decade… • Arose from solution need (then and now) Seven Bridges of Konigsberg problem. Leonhard Euler, 1735
  18. Java domain • Find field changes between Java 17 and

    Java 8? • Update doc URL for a Class • Find most similar diffs (which affected same components)
  19. Enter stage right - graphs • Document path (not just

    data) • Answering how and why • Understanding connections • Find alternates, impacts, etc • Produce better assumptions, decisions
  20. Neo4j

  21. Extremes in Development

  22. Stability • ACID compliance • Relationships at write vs read

    • Scaling (vertical+horizontal)
  23. Innovation • Cypher vs SQL • Schema-less vs schema-enforced •

    Graph modeling vs ERD • Integrations • Cloud/on-premises solutions
  24. Java dev: Why Graph?

  25. Java domain • Java Versions (i.e. 8, 11, 17) •

    Changes between versions over time • Diffs
  26. Java Entity - Domain Class • Class • Entity/Object •

    Represents domain type • General outline for objects of that type • Variables/properties • Details for that entity • Values may not always exist • Constructor - instance of object • Each instance is unique object with varying info
  27. Demo: Let’s create one

  28. Java Domain Relationships • Adding relationships • Add variable as

    pointer to another object • Links entities together • Might have some annotations for mapping
  29. Demo: Let’s add that

  30. Graph Data Model

  31. Property Graph • Node (vertex) • Relationship (edge)

  32. Nodes • Represent objects or entities • Can be labeled

    JavaVersion VersionDiff
  33. Nodes • Represent objects or entities • Can be labeled

    • May have properties JavaVersion VersionDiff version: “17” gaDate: 2021-09-14 fromVersion: “17.0.3+7-tem” toVersion: “1.6.0_45-oracle” JavaVersion version: “6” gaDate: 2006-12-12 codeName: “Mustang”
  34. Relationships • Must have a type • Must have a

    direction FROM_NEWER JavaVersion VersionDiff version: “17”
  35. Relationships • Must have a type • Must have a

    direction • May have properties M IG RATES versionSteps: 3 FROM_NEWER JavaVersion VersionDiff version: “17”
  36. Relationships • Must have a type • Must have a

    direction • May have properties • Nodes can share multiple relationships M IG RATES versionSteps: 3 FROM_NEWER JavaVersion VersionDiff version: “17”
  37. Label • A group of nodes • Like a category

    • Domain class :) Person
  38. Label • A group of nodes • Like a category

    • Domain class :) Person Employee Customer
  39. Property • Key-value pair • Associated with node or relationship

    • Like a variable name and value M IG RATES versionSteps: 3 JavaVersion version: “17” JavaVersion version: “6” gaDate: 2021-09-14 gaDate: 2006-12-12 codeName: “Mustang”
  40. Demo model

  41. Whiteboard-friendliness

  42. JDK Full Data Model

  43. JDK Data Model

  44. Java devs: Why Choose Graphs? • Data model match -

    application to database • Less data model mapping = more efficient application coding
  45. Other types of graphs? • Resource Description Framework (RDF) •

    Triples: subject (node), predicate (rel), object (node) • Often web-based data • Often XML format
  46. Query in a Graph vs Relational DB

  47. SQL vs Cypher SELECT j.JavaVersion, j.Status, j.GaDate, j.EolDate, d.fromVendor, d.fromVersion,

    d.toVendor, d.toVersion FROM JavaVersion j LEFT JOIN DiffList dl ON dl.JavaVersion = j.JavaVersion LEFT JOIN VersionDiff d ON dl.FromVersion = d.FromVersion; MATCH (j:JavaVersion)-[r:FROM_NEWER]->(d:VersionDiff) RETURN j, r, d; SQL Cypher JavaVersion VersionDiff DiffList JavaVersion VersionDiff
  48. 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 )
  49. Cypher: powerful and expressive Jennifer Neo4j WORKS_FOR CREATE (:Person {

    name: ‘Jennifer’}) -[:WORKS_FOR]-> (:Company { name: ‘Neo4j’}) NODE PROPERTY NODE PROPERTY LABEL LABEL
  50. Cypher: read Jennifer Neo4j WORKS_FOR MATCH (:Person { name: ‘Jennifer’}

    ) -[:WORKS_FOR]-> ( whom ) 
 RETURN whom
  51. Let’s Query!

  52. Java Ecosystem • Language drivers • Framework support • Spring,

    Quarkus, Micronaut, etc • Connectors • APOC, Neosemantics, ETL, Spark, etc • Visualization tools • Import/export • Database integrations
  53. Let’s code!

  54. Keep in mind… • Relational • JPA or Hibernate ▪

    Mismatch between models ▪ Set theory and relational algebra • Graph • Neo4j ▪ More object-oriented model ▪ Based on graph theory and network theory
  55. Resources • Code: github.com/JMHReif/pouring-coffee-into-matrix-lombok • Neo4j AuraDB: bit.ly/neo4j-aura • Blog:

    bit.ly/jmhreif-blog Jennifer Reif Email: jennifer.reif@neo4j.com Twitter: @JMHReif Website: jmhreif.com