Graph databases

The property graph: nodes, directed and typed relationships, labels, properties; modelling a domain as a graph, walking from neighbour to neighbour without joins, and the typical uses.

  • 25 cards
  • 5 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. Sort and link
  4. Scenarios
  5. Understand

A few cards from the deck

  • Graph database: what is it?

    Show the answer

    A database whose data are entities linked to one another, and which keeps those links directly attached to the entities so that they can be followed without recomputation.

    Links are first-class data, already stored: following a relationship costs the same whether the database holds a thousand or a hundred million nodes.

  • In this friendship graph (FRIEND relationships in both directions), who are Lea's friends of friends, meaning two hops away, excluding Lea and her direct friends?

    ```text
    Lea – Sam
    Lea – Ines
    Sam – Ines
    Sam – Noe
    Ines – Zoe
    `

    • Noe and Zoe
    • Sam and Ines
    • Noe only
    • Sam, Ines, Noe and Zoe
    Show the answer

    Noe and Zoe

    Lea's direct friends are Sam and Ines (one hop). Their friends are Lea, Ines, Noe (for Sam) and Lea, Sam, Zoe (for Ines). Once Lea, Sam and Ines are excluded, Noe and Zoe remain.

  • In a property graph, a relationship always has a … (it goes from one node to another) and a … (for example FRIEND or DIRECTED).

    Show the answer

    In a property graph, a relationship always has a direction (it goes from one node to another) and a type (for example FRIEND or DIRECTED).

    Direction matters: (a)-[:DIRECTED]->(f) says a directed f, not the reverse. A symmetric relationship, like a friendship, can be read in both directions at query time.

  • Property graph: what is it?

    Show the answer

    A model made of nodes and directed, typed relationships, where each node or relationship can carry name-value properties.

    In (:Person {name:'Keanu'})-[:ACTED_IN {role:'Neo'}]->(:Movie), the relationship has a type, a direction and its own property, role.

  • "Friends of friends of friends" takes 30 seconds in SQL, with three self-joins on 50 million rows. What is the cause, and the solution?

    • The table lacks columns; one must be added per hop
    • SQL cannot follow relationships; the result must be stored in a JSON field
    • Friendships are stored in the wrong direction; simply reverse them
    • Each hop redoes a join on the big table; a graph just follows links
    Show the answer

    Each hop redoes a join on the big table; a graph just follows links

    SQL can run the query, but each self-join walks a big table with an index. In a graph you start from a node and follow relationships directly: the work follows the number of neighbours met.