Why Graphs Matter: An Introduction to Relational Data
Look around you: the connections between people, molecules, ideas, and systems are not random noise—they follow structured relational patterns that define how our world works. For decades, machine learning practitioners have relied on tabular data, images, and text as their primary data formats, but these representations often fail to capture the rich relational context that underpins most real-world phenomena. This is where graphs shine: as a universal, flexible data structure that explicitly models entities and the relationships between them, graphs unlock insights that are impossible to extract from traditional data formats. In this chapter, we will demystify graph data, explain why it is the most natural way to represent relational information, compare it to the data formats you may already be familiar with, and guide you through three hands-on exercises to build your first graph data projects from scratch—no prior graph theory experience required.
The Real World Runs on Relationships
Every system you interact with daily is built on relationships: your social circle is defined by friendships and professional connections, the drugs you take are made of molecules whose properties depend on how their atoms bond together, the navigation app you use to commute relies on road networks connecting intersections, and the recommendation feed on your favorite e-commerce platform is powered by connections between users and products. For a long time, we lacked a unified way to represent these relationships in a format that machines could understand and learn from—until graph data structures became mainstream in machine learning.
Let’s take a concrete example to see the limitations of traditional data formats. Imagine you want to build a model to predict whether a new drug molecule will be toxic to humans. The molecule is made of 17 atoms: 8 carbon atoms, 10 hydrogen atoms, 2 nitrogen atoms, and 1 oxygen atom, connected by 19 chemical bonds (single, double, and triple bonds). If you try to store this molecule in a tabular format, you run into a core problem: every molecule has a different number of atoms. You could create 100 columns for the maximum possible number of atoms in your dataset, but most molecules will have empty cells for unused columns, leading to extreme sparsity. Worse, the tabular format completely discards the structural information about which atoms are connected to which—if you shuffle the rows of the table, you lose all information about the molecule’s structure, even though the molecule itself is unchanged. If you try to represent the molecule as an image, you would have to map atoms to pixels, but there is no standard grid layout for molecules, and you would lose critical information about bond types and atom connectivity.
This is where graph data solves the problem natively. For the molecule above, you can create a graph where each atom is a node, each chemical bond is an edge, and each node stores the atom type as a feature, while each edge stores the bond type as a feature. The graph has no fixed size: a molecule with 5 atoms and a molecule with 100 atoms can both be represented in the same format, with no wasted space or lost structural information. This is the core power of graph data: it is a universal representation that matches the structure of relational data in the real world.
Common Real-World Graph Data Scenarios
To help you build intuition, let’s walk through five of the most common graph data use cases, each illustrating a different strength of graph representation:
1. Social Networks The most familiar example of graph data is social networks like Facebook, WeChat, or X (Twitter). In these networks, each user is a node, and edges represent relationships between users: friendships, follows, mentions, or interactions. Node features include user demographics, post history, and profile information, while edge features include interaction frequency, message content, or relationship duration. Graph representation is perfect for social networks because it natively captures multi-hop relationships: for example, the “friends of your friends” who may become your future connections, or the spread of a viral post through a chain of shares. Traditional tabular models can only capture one-hop relationships (e.g., “user A is friends with user B”) but fail to model the broader network context that drives social dynamics.
2. Molecular and Biological Networks In drug discovery and bioinformatics, molecules and biological systems are inherently graph-structured. A molecule is a graph where nodes are atoms (C, H, O, N, etc.) and edges are chemical bonds (single, double, triple). Node features include atom charge and mass, while edge features include bond length and type. Protein-protein interaction networks, where nodes are proteins and edges represent physical interactions between them, are also represented as graphs. The ability of graphs to represent variable-sized, irregular structures makes them ideal for molecular modeling: a small molecule with 10 atoms and a large protein with 10,000 amino acids can be processed by the same graph model without modification. This is the foundation of systems like DeepMind’s AlphaFold, which uses graph neural networks to predict protein 3D structures with near-experimental accuracy, revolutionizing biology and drug discovery.
3. Knowledge Graphs Knowledge graphs are structured repositories of factual information, where nodes are real-world entities (people, places, events, concepts) and edges are semantic relationships between them (e.g., “born in”, “located in”, “CEO of”). A typical knowledge graph stores billions of triples in the form of (subject, relation, object), such as (Elon Musk, CEO of, Tesla) or (Paris, capital of, France). Knowledge graphs power the “knowledge panels” you see on Google Search, and are now a core component of retrieval-augmented generation (RAG) systems for large language models, reducing hallucinations by providing factual, structured context. Unlike unstructured text, knowledge graphs explicitly model relationships between entities, making it easy to answer complex questions like “What companies has Elon Musk led that are based in the US?”
4. Recommendation Systems Modern recommendation systems use graphs to model the complex web of interactions between users and items (products, videos, articles). In a recommendation graph, there are two types of nodes: user nodes and item nodes. Edges represent interactions between users and items: clicks, purchases, likes, or views. Node features include user demographics and item attributes, while edge features include interaction time and rating. Graph-based recommendation models can capture high-order relationships that traditional collaborative filtering models miss: for example, “users who are similar to you bought items you haven’t seen” or “items that are frequently bought together with items you’ve purchased”. Major e-commerce platforms like Alibaba and Amazon use graph-based recommendation systems, which have been shown to increase click-through rates by 20-30% compared to traditional methods.
5. Transportation and Logistics Networks Transportation networks are perhaps the oldest use case for graph data. Road networks, rail networks, and airline routes are all graphs where nodes are intersections, stations, or airports, and edges are roads, rail lines, or flight paths. Edge weights represent travel time, distance, or congestion level. Navigation apps like Google Maps and Waze use graph algorithms to calculate the shortest path between two locations, and update edge weights in real time to account for traffic, accidents, or road closures. In logistics, graph models are used to optimize delivery routes, allocate warehouse resources, and predict shipment delays.
Core Components of Graph Data
Before we dive deeper, let’s formalize the basic components of a graph, using simple