# Thinking in Graphs

A Tech Talk, 3/3/23

# What We'll Cover

• What data graphs are / can be
• How to think about your data in a graph
• How data graphs differ from other data modeling approaches
• The value of data graphs
• When to use a data graph

# What is a data graph?

## What is a data graph?

• A data graph is an approach to structuring data that is focused on relationships between entities.
• It's non-linear architecture allows for more flexibility and enables you to create connections between disparate pieces of data to provide new and powerful insights.
• When we talk about data within a data graph we generally refer to entities as "nodes", and connections between entities as "edges".

## How do they work?

• Based on graph theory, a mathematical approach to model pairwise relations between objects.
• It connects vertices in a network through edges.

# How we got here

• Driven by a more recent change in how we think about data, which impacted how we structure it.
• Thinking shifted from how to most efficiently store data to how to get the most value out of it.
• Realization that data is inherently more valuable when it is connected.

# The gold rush

GraphQL

Stardog

DGraph

## Notable implementations

A shift in mindset needs to occur in order to see the value [in data graphs]. This mindset is a shift from thinking about your data in a table to prioritizing the relationships across it.

- Matthias Broecheler

# Shifting our mindset

## Trees vs. Graphs

• All trees are Graphs, but not all graphs are trees...
• Trees are linear, they have a single root node and flow in a single direction.
• Can connect to other leaf nodes or more subtrees, but connections happen in a specific order.

## Trees vs. Graphs

• Graphs are omnidirectional
• They have no defined end or beginning, they have multiple "entrypoints"
• Connections to nodes within a graph can be

## Relational vs. Graph

• Relational model uses foreign keys to relate data together.
• Relational focuses on storing tabular data for people, places, and things.
• Graphs make it easier to create richer data connections with edges.

## What does a healthy data graph look like?

• Many connections on each node, and many paths to each node through various entrypoints.
• Common entities referenced throughout the graph, enriched with relationship-specific data via edges.
• Few if-any "dead ends" within the graph where nodes are only accessible via a single entrypoint.

# Edges

## Edges

• Edges are the connections between nodes within a graph
• They often contain data that can be attributed to the relationship of the nodes
• You can have directed or bidirectional edges within a graph

## Bidirectional Edges

• Bidirectional edges represent connections to nodes within a graph regardless of direction.
• In this example, the relationship between me and my dad can always be considered "family".

## Directional Edges

• Directional edges represent connections to nodes where directionality does matter.
• In this example we are looking at a graph of twitter followers. Me and Elon Musk are followed by Russian bots, and I follow Elon musk, but Elon doesn't follow me and neither of us follow the Russian bots.

## The value of a data graph

• Allows us to enrich connections from disparate data sources with highly valuable information.
• We can use edge data to personalize experiences for the user.
• Personalized experiences can lead to better customer engagement & ultimately revenue.

## How we leverage data graphs at NerdWallet

``````{
review {
title
authors {
name
}
categories {
id
articles {
title
authors {
name
}
}
}
marketplaceEntity {
id
name
review {
id
title
}
}
}
}``````

## When to leverage a data graph

• A lot of the data you need is derived from the relationship between entities.
• Most of the complexity within your implementation will be around creating relationships between entities.
• Your entity models change often, and are highly connected to other models.

# Takeaways

• Data graphs can be an effective tool for extracting more value from your data.
• Data graphs can help create more meaningful connections by enriching them with edge data.
• When working with data graphs we need to stop thinking about data linearly, and embrace graph thinking when modeling nodes and edges for a data graph.