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!

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: [email protected] Twitter: @JMHReif Website: jmhreif.com
  2. Who Am I? - Jennifer • Developer + Advocate •

    Continuous learner • Conference speaker • Blogger • Geek Jennifer Reif Email: [email protected] 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. Databases • Database: a structured set of data held in

    a computer, especially one that is accessible in various ways • Relational? NoSQL? Other?
  6. Relational Database • No data model limitations • Memory-efficient for

    both read and write • CPU-intensive • Difficult query language
  7. 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" }
  8. 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" }
  9. Graph Database • No CPU vs Memory/Storage tradeoff (as in

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

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

    • JDBC Template • JOOQ • JPA or Hibernate • NoSQL - Document • MongoDB • Graph • Neo4j
  12. 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
  13. 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)
  14. Enter stage right - graphs • Document path (not just

    data) • Answering how and why • Understanding connections • Find alternates, impacts, etc • Produce better assumptions, decisions
  15. Innovation • Cypher vs SQL • Schema-less vs schema-enforced •

    Graph modeling vs ERD • Integrations • Cloud/on-premises solutions
  16. Java domain • Java Versions (i.e. 8, 11, 17) •

    Changes between versions over time • Diffs
  17. 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
  18. Java Domain Relationships • Adding relationships • Add variable as

    pointer to another object • Links entities together • Might have some annotations for mapping
  19. 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”
  20. Relationships • Must have a type • Must have a

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

    direction • May have properties M IG RATES versionSteps: 3 FROM_NEWER JavaVersion VersionDiff version: “17”
  22. 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”
  23. Label • A group of nodes • Like a category

    • Domain class :) Person Employee Customer
  24. 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”
  25. Java devs: Why Choose Graphs? • Data model match -

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

    Triples: subject (node), predicate (rel), object (node) • Often web-based data • Often XML format
  27. 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
  28. 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 )
  29. Cypher: powerful and expressive Jennifer Neo4j WORKS_FOR CREATE (:Person {

    name: ‘Jennifer’}) -[:WORKS_FOR]-> (:Company { name: ‘Neo4j’}) NODE PROPERTY NODE PROPERTY LABEL LABEL
  30. Java Ecosystem • Language drivers • Framework support • Spring,

    Quarkus, Micronaut, etc • Connectors • APOC, Neosemantics, ETL, Spark, etc • Visualization tools • Import/export • Database integrations
  31. 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