modeling with graphs
play

MODELING WITH GRAPHS Alistair Jones Neo Technology What is modeling? - PowerPoint PPT Presentation

MODELING WITH GRAPHS Alistair Jones Neo Technology What is modeling? Model Complexity Simple Complex Key-Value Document Column Graph Relational This talk compares Relational Whats a graph? Social ( network


  1. MODELING WITH GRAPHS Alistair Jones Neo Technology �

  2. What is modeling?

  3. Model Complexity � Simple � Complex � Key-Value � Document � Column � Graph � Relational �

  4. This talk compares Relational �

  5. What’s a graph?

  6. Social ( network | graph )

  7. What language do they speak here? Language ¡ Country ¡

  8. What language do they speak here? Language ¡ Country ¡

  9. What language do they speak here? Language ¡ Country ¡

  10. Tables Language ¡ Country ¡ language_code ¡ country_code ¡ language_name ¡ country_name ¡ word_count ¡ flag_uri ¡

  11. Need to model the relationship Language ¡ Country ¡ language_code ¡ country_code ¡ language_name ¡ country_name ¡ word_count ¡ flag_uri ¡ language_code ¡

  12. What if the cardinality changes? Language ¡ Country ¡ language_code ¡ country_code ¡ language_name ¡ country_name ¡ word_count ¡ flag_uri ¡ country_code ¡ ¡

  13. Or we go many-to-many? Language ¡ LanguageCountry ¡ Country ¡ language_code ¡ language_code ¡ country_code ¡ country_code ¡ language_name ¡ country_name ¡ word_count ¡ flag_uri ¡ ¡

  14. Or we want to qualify the relationship? Language ¡ LanguageCountry ¡ Country ¡ language_code ¡ language_code ¡ country_code ¡ country_code ¡ language_name ¡ country_name ¡ primary ¡ word_count ¡ flag_uri ¡ ¡

  15. Explicit Relationship Language ¡ Country ¡ name ¡ name ¡ IS_SPOKEN_IN ¡ word_count ¡ flag_uri ¡ ¡

  16. Japanese Japanese Japanese Arabic Arabic Arabic Japan Japan Japan Iraq Iraq Iraq Hebrew Hebrew Hebrew Egypt Egypt Egypt Israel Israel Israel Germany Germany Germany Finnish Finnish Finnish Austria Austria Austria Finland Finland Finland Danish Danish Danish German German German Romansh Romansh Romansh Dutch Dutch Dutch Denmark Denmark Denmark Switzerland Switzerland Switzerland Sri Lanka Sri Lanka Sri Lanka Italy Italy Italy Belgium Belgium Belgium Italian Italian Italian Czech Czech Czech Czech Czech Czech Tamil Tamil Tamil Sinhala Sinhala Sinhala French French French France France France Simplified Chinese Simplified Chinese Simplified Chinese China China China Canada Canada Canada Mandarin Mandarin Mandarin Romanian Romanian Romanian Australia Australia Australia Afrikaans Afrikaans Afrikaans Romania Romania Romania South Africa South Africa South Africa Argentina Argentina Argentina India India India English English English Hindi Hindi Hindi Ireland Ireland Ireland Spanish Spanish Spanish United Kingdom United Kingdom United Kingdom Portuguese Portuguese Portuguese Pakistan Pakistan Pakistan Icelandic Icelandic Icelandic Irish Irish Irish Welsh Welsh Welsh Brazil Brazil Brazil Spain Spain Spain Iceland Iceland Iceland Urdu Urdu Urdu Catalan Catalan Catalan Thailan Thailan Thailan Thai Thai Thai Turkish Turkish Turkish Turkey Turkey Turkey

  17. Relationship Properties Language ¡ Country ¡ name ¡ name ¡ IS_SPOKEN_IN ¡ word_count ¡ flag_uri ¡ ¡ as_primary ¡

  18. What’s different? IS_SPOKEN_IN ¡ Language ¡ LanguageCountry ¡ Country ¡ language_code ¡ language_code ¡ country_code ¡ country_code ¡ language_name ¡ country_name ¡ primary ¡ word_count ¡ flag_uri ¡ ¡

  19. What’s different? • Implementation of maintaining relationships is left up to the database • Surrogate keys disappear or are unnecessary (with the exception of node id) • Relationships get an explicit name

  20. Relationship specialisation Language ¡ Country ¡ name ¡ name ¡ IS_SPOKEN_IN ¡ word_count ¡ flag_uri ¡ ¡ as_primary ¡

  21. Weighted relationships Language ¡ Country ¡ name ¡ name ¡ POPULATION_SPEAKS ¡ word_count ¡ flag_uri ¡ ¡ populaAon_fracAon ¡

  22. Bidirectional relationships Language ¡ Country ¡ name ¡ name ¡ IS_SPOKEN_IN ¡ word_count ¡ flag_uri ¡ PRIMARY_LANGUAGE ¡ ¡

  23. Keep on adding relationships Language ¡ Country ¡ name ¡ name ¡ POPULATION_SPEAKS ¡ word_count ¡ flag_uri ¡ ¡ populaAon_fracAon ¡ SIMILAR_TO ¡ ADJACENT_TO ¡

  24. Graph Modeling Principles 1 ¡ 2 ¡ 3 ¡

  25. Graph Modeling Principles Paradigm 2 ¡ 3 ¡ Embrace the

  26. Use the building blocks • Nodes • Relationships RELATIONSHIP_NAME ¡ • Properties name: ¡value ¡

  27. Anti-pattern: rich properties name: ¡“Canada” ¡ languages_spoken: ¡“[ ¡‘English’, ¡‘French’ ¡]” ¡ ¡ ¡

  28. Graph Modeling Principles 3 ¡ Embrace Nodes for the Identity Paradigm

  29. Node represents multiple concepts Country ¡ name ¡ flag_uri ¡ language_name ¡ number_of_words ¡ yes_in_langauge ¡ no_in_language ¡ currency_code ¡ currency_name ¡

  30. Break out separate concepts Country ¡ Country ¡ name ¡ name ¡ SPEAKS ¡ flag_uri ¡ number_of_words ¡ currency_code ¡ yes ¡ currency_name ¡ no ¡ ¡ Currency ¡ currency_code ¡ currency_name ¡ USES_CURRENCY ¡

  31. Property represents entity Employee ¡ Workplace ¡ name: ¡“Alistair” ¡ name: ¡“Neo ¡Tech” ¡ WORKS_AT ¡ ¡ role: ¡“soXware ¡engineer” ¡

  32. ( Reify | Nodify ) connecting entities Employee ¡ Workplace ¡ Role ¡ name: ¡“Alistair” ¡ name: ¡“Neo ¡Tech” ¡ name: ¡“soXware ¡ engineer” ¡ ¡ ROLE ¡ start_date: ¡Aug-­‑2011 ¡ EMPLOYEE ¡ EMPLOYED_IN ¡ Employment ¡

  33. Graph Modeling Principles Embrace Relation- Nodes for the ships for Identity Paradigm Access

  34. Japanese Japanese Japanese Arabic Arabic Arabic Japan Japan Japan Iraq Iraq Iraq Hebrew Hebrew Hebrew Egypt Egypt Egypt Israel Israel Israel Germany Germany Germany Finnish Finnish Finnish Austria Austria Austria Finland Finland Finland Danish Danish Danish German German German Romansh Romansh Romansh Dutch Dutch Dutch Denmark Denmark Denmark Switzerland Switzerland Switzerland Sri Lanka Sri Lanka Sri Lanka Italy Italy Italy Belgium Belgium Belgium Italian Italian Italian Czech Czech Czech Czech Czech Czech Tamil Tamil Tamil Sinhala Sinhala Sinhala French French French France France France Simplified Chinese Simplified Chinese Simplified Chinese China China China Canada Canada Canada Mandarin Mandarin Mandarin Romanian Romanian Romanian Australia Australia Australia Afrikaans Afrikaans Afrikaans Romania Romania Romania South Africa South Africa South Africa Argentina Argentina Argentina India India India English English English Hindi Hindi Hindi Ireland Ireland Ireland Spanish Spanish Spanish United Kingdom United Kingdom United Kingdom Portuguese Portuguese Portuguese Pakistan Pakistan Pakistan Icelandic Icelandic Icelandic Irish Irish Irish Welsh Welsh Welsh Brazil Brazil Brazil Spain Spain Spain Iceland Iceland Iceland Urdu Urdu Urdu Catalan Catalan Catalan Thailan Thailan Thailan Thai Thai Thai Turkish Turkish Turkish Turkey Turkey Turkey

  35. Relationships for querying • Relationships should the primary means to access nodes in the database • Traversing relationships is cheap – that’s the whole design goal of a graph database • Use indexes only to find starting nodes for a query

  36. Anti-pattern: unconnected graph name: ¡“Jones” ¡ name: ¡“Jones” ¡ name: ¡“Jones” ¡ name: ¡“Jones” ¡ name: ¡“Jones” ¡ name: ¡“Jones” ¡ name: ¡“Jones” ¡ name: ¡“Jones” ¡ name: ¡“Jones” ¡ name: ¡“Jones” ¡ name: ¡“Jones” ¡

  37. Challenge: Property or Relationship? • Can every property be replaced by a relationship? • Should every entities with the same property values be connected?

  38. Object Mapping • Similar to how you would map objects to a relational database, using an ORM such as Hibernate • Generally simpler and easier to reason about • Examples – Java: Spring Data Graph – Ruby: Active Model

  39. Aside: why map? • Do you use mapping because you are scared of SQL? • Following DDD, could you write your repositories directly against the graph API?

  40. Graph Modeling Principles Embrace Relation- Nodes for the ships for Identity Paradigm Access

  41. Alistair ¡Jones ¡ alistair.jones@neotechnology.com ¡ @apcj ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend