<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <title>Data Bene - Tag: 'Graph database'</title>
  <subtitle>Relational database, open-source and scalable.</subtitle>
  <link href="https://www.data-bene.io/en/blog/tags/graph-database.xml" rel="self" type="application/atom+xml" />
  <updated>2026-10-19T00:00:00Z</updated>
  <id>https://www.data-bene.io/en/blog/tags/graph-database.xml</id>
    <entry>
      <title>PostgreSQL as a graph database, part 0: intro, graphs, graph databases</title>
      <link href="https://www.data-bene.io/en/blog/postgresql-as-a-graph-database/" />
      <updated>2026-10-19T00:00:00Z</updated>
      <id>https://www.data-bene.io/en/blog/postgresql-as-a-graph-database/</id>
     <content type="html"><![CDATA[ <p><em>This is the first post in a series exploring graph databases and PostgreSQL’s evolving role in the graph landscape. Over four posts, we’ll move from foundational concepts through PostgreSQL’s SQL/PGQ implementation details and its future, benchmark comparisons against PostgreSQL graph solutions (e.g Apache AGE) , and finally the broader trajectory of relational systems absorbing graph workloads.<br>
The series assumes no prior graph database expertise.</em></p>
<h2 id="what-is-a-graph"><a class="heading-anchor" href="#what-is-a-graph">What Is a Graph?</a></h2>
<p><strong>A graph is a set of things and a set of connections between them</strong>. That is the whole definition.<br>
The things are called <em>vertices</em> (or nodes) and the connections are called <em>edges</em> (or relationships).</p>
<p>Formally, a graph $G $ is modeled as a tuple $(V, E)$, where $V $ is a set of vertices and $E $  is a subset of the Cartesian product of $V $ with itself, representing a set of edges:<br>
$E \subseteq V \times V$</p>
<p>We find 3 kinds of graphs: directed, undirected, and weighted.</p>
<ol class="list">
<li>
<p>For a <strong>directed graph</strong>, an edge $E $ equals the ordered pair $(u, v)$ in $E $, where $u $ is the source vertex and $V $ is the destination vertex; an example is a Twitter follow, where the relationship has a specific direction:<br>
edge $e = (u, v) \in E$</p>
</li>
<li>
<p>For an <strong>undirected graph</strong>, an edge $E $ is an unordered pair containing $u $ and $V $ in $E $; an example is a Facebook friendship, where the relationship is mutual:<br>
edge $e = \{ u, v \} \in E$</p>
</li>
<li>
<p>A <strong>weighted graph</strong> extends this structure as a triple $(V, E, w)$, where $w $ is a function that asigns each edge in $E $ a real number (a weight), which is useful for representing distances, costs, or strengths:<br>
triple $(V, E, w)$ where $w: E \to \mathbb{R}$</p>
</li>
</ol>
<!--Formally, a graph $G $ is modeled as a tuple $(V, E)$ where $V $ is a set of vertices and $E \subseteq V \times V$ is a set of edges. We write $|V| = n$ and $|E| = m$. For a directed graph, an edge $e = (u, v) \in E$ is an ordered pair where $u $ is the source vertex and $V $ is the destination (think Twitter follows, where the relationship has a direction). For an undirected graph, an edge $e = \{u, v\} \in E$ is an unordered pair (think Facebook friendships, where the relationship is mutual). A weighted graph extends this as a triple $(V, E, w)$ where $w: E \to \mathbb{R}$ maps each edge to a real-valued weight, useful for representing distances, costs, strengths…-->
<h2 id="what-can-be-a-graph"><a class="heading-anchor" href="#what-can-be-a-graph">What Can Be a Graph?</a></h2>
<p>The power of the graph model lies in its universality. Once you start looking, graphs are everywhere.</p>
<ul class="list">
<li><strong>Social networks</strong> represent friendship, followership, and interaction as edges connecting user vertices.<br>
<em>Does Alice know Bob through other people?</em><br>
<em>Is basically walking the graph and finding this relationship.</em></li>
</ul>
<ul class="list">
<li>
<p><strong>Fraud detection systems</strong> model transactions and accounts as graphs, exploiting the fact that fraudulent rings are just cycles or dense cluster of accounts and transactions.<br>
<em>The relationships between entities often reveal fraud more reliably than the entities themselves.</em></p>
</li>
<li>
<p><strong>Supply chain and logistics</strong> applications use graphs to model dependencies between suppliers, warehouses, and shipments.</p>
</li>
<li>
<p>Biologists represent <strong>protein interaction networks and drug-target</strong> relationships.<br>
<img src="/assets/images/blog/protein_network_transparent.png" alt="protein_network_transparent" src="/assets/images/blog/protein_network_transparent.png" alt="" width="80%" eleventy:widths="650,960,1400"></p>
</li>
<li>
<p><strong>Networks</strong> use graphs to represent topologies.</p>
</li>
</ul>
<p><img src="/assets/images/blog/stp_topology_transparent.png" alt="stp_topology_transparent" src="/assets/images/blog/stp_topology_transparent.png" alt="" width="80%" eleventy:widths="650,960,1400"></p>
<ul class="list">
<li><strong>The web</strong> is another example.<br>
<em>Pages are vertices, hyperlinks are directed edges, and the resulting graph is one of the largest and most studied structures in computing</em>:</li>
</ul>
<p><img src="/assets/images/blog/web_graph_transparent.png" alt="web_graph_transparent" src="/assets/images/blog/web_graph_transparent.png" alt="" width="80%" eleventy:widths="650,960,1400"></p>
<h2 id="modeling-as-a-graph"><a class="heading-anchor" href="#modeling-as-a-graph">Modeling as a graph</a></h2>
<p>What the above domain examples share are <strong>Properties</strong> that make a <strong>Graph</strong> an intuitive solution for us human beings. Relationships are as important as the entities themselves.<br>
The schema is often irregular or evolving. <strong>Queries</strong> frequently follow chains of connections whose length or shape is not known in advance.</p>
<p><strong>Graphs are also effective because they are easy to reason about visually</strong>. Human beings understand things better with examples, and a graph makes relationships explicit. That visual and structural clarity often translates into data models and algorithms that are easier to explain, and question.</p>
<p>The model defined at the start of this post, a set of vertices and a set of edges with no data attached to either of them, underlies much of classical graph theory and is the basis for graph processing frameworks and graph database management systems. It is, however, too limited for most real-world database scenarios, because it carries no information beyond structure. The richer models used in graph databases are built on top of it.</p>
<ul class="list">
<li>The <strong>Labeled Property Graph (LPG)</strong> is the standard conceptual model used by most graph database systems. It enriches the simple graph with two mechanisms: <strong>labels</strong>, which classify vertices and edges into types, and <strong>properties</strong>, which attach arbitrary key-value data to individual vertices and edges.<br>
A vertex might have the label <code>Person</code> and properties <code>name='Alice' and age=21</code>.<br>
An edge might have the label <code>KNOWS</code> and a property <code>since = &quot;09.08.2007&quot;</code>.</li>
</ul>
<p><a href="https://dl.acm.org/doi/10.1145/3604932#sec-3-3-2" target="_blank" rel="noopener"><img src="/assets/images/blog/csur-2022-0455-f02.png" alt="Labeled Property Graph example, Adapted from Besta et al" src="/assets/images/blog/csur-2022-0455-f02.png" alt="" width="80%" eleventy:widths="650,960,1400"></a></p>
<p>There are other variants of LPG implemented by others systems with minor extensions or restrictions, <a href="https://neo4j.com/" target="_blank" rel="noopener">Neo4j</a> for example supports an arbitrary number of labels per vertex but restricts edges to exactly one label.</p>
<ul class="list">
<li>The <strong>Resource Description Framework (RDF)</strong> takes a different approach. RDF represents information as collections of triples subject, predicate, object $(s, p, o)$.<br>
While RDF-based systems are a meaningful part of the graph database landscape, they follow a different data model than LPG and <strong>are outside the scope of this series</strong>. We mention it only for context, as this article series is focused on labeled property graph databases.</li>
</ul>
<h2 id="the-many-forms-of-graph-databases"><a class="heading-anchor" href="#the-many-forms-of-graph-databases">The Many Forms of Graph Databases</a></h2>
<p>The graph database landscape is heterogeneous. Systems differ fundamentally in how they store graphs, what data models they support, and what query languages they expose.</p>
<p><a href="https://dl.acm.org/doi/10.1145/3604932#sec-5" target="_blank" rel="noopener"><img src="/assets/images/blog/graph_db_models_transparent.png" alt="Overview of different graph storage backends" src="/assets/images/blog/graph_db_models_transparent.png" alt="" width="80%" eleventy:widths="650,960,1400"></a></p>
<p><strong>Native graph databases</strong> are built from the ground up around the graph model. Their storage layouts and query engines are designed with graph access patterns as the primary concern: they aim to “follow pointers”, or otherwise access adjacency directly, so that traversal “does not become a JOIN”.<br>
Neo4j is the most prominent example. For a long time its storage engine used fixed-size records with direct pointers between them, and this design was mostly how people described native graph storage.<br>
After nearly 15 years, in 2024, Neo4j introduced a block format that colocates related data into variable-length blocks inside pages <sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup>. Although a late realization (for the better), it implies that “native equals pointer chasing” description is no longer fully accurate.<br>
The useful definition therefore should be behavioral, meaning native systems try to make adjacency access direct, whether through pointers, colocated blocks, or other graph-specific layouts.</p>
<p><strong>Non-native graph databases</strong> take an existing mature backend; a relational, document or key-value store and build graph capabilities on top of it <sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup>. Both classes are graph databases in the sense that they store, query, and manage graph data, but their internals are fundamentally different implying which graph-specific optimizations are available and which are left to the backend.<br>
In practice, the difference is more about where the engineering effort goes, for example non-native systems inherit decades of work in concurrency control, indexing, query optimization and many other DBMS components.</p>
<hr>
<p><strong>A survey</strong> of approximately one hundred graph database systems reveals that roughly 66% are non-native. The distribution of underlying data models breaks down as: 34% native graph storage, 24% relational databases, 24% key-value or wide-column stores, and 18% document stores. This makes sense, one would want to make an existing DBMS capable of supporting graph queries if possible, providing users with the best possible interface.</p>
<p>This is precisely where PostgreSQL enters the picture. As a mature relational database, it represents a massive share of that non-native ecosystem through extensions and new SQL standards.</p>
<!-- *That is enough vocabulary to start. In the next post, we look at SQL/PGQ in PostgreSQL: what it does, how it is implemented, and where it stands today.* -->
<h2 id="key-takeaways"><a class="heading-anchor" href="#key-takeaways">Key Takeaways</a></h2>
<p>Before we jump into the technical implementation, let’s lock in the core concepts from this introduction:</p>
<ul class="list">
<li><strong>Graphs are universal:</strong> At their core, they are just vertices (nodes) and edges (relationships), making them ideal for complex, interconnected data like social networks or fraud rings.</li>
<li><strong>LPG is the industry standard:</strong> The Labeled Property Graph model extends simple graphs by allowing you to attach labels and key-value properties to both nodes and edges.</li>
<li><strong>Native vs. Non-Native is behavioral:</strong> Native databases (like Neo4j) optimize for direct adjacency access, while non-native databases leverage existing enterprise-grade engines (relational, document) to handle graph workloads.</li>
<li><strong>The landscape is hybrid:</strong> Over 66% of graph database solutions are built on top of non-graph backends, proving that you don’t always need to deploy a new native database to query graph structures.</li>
</ul>
<h2 id="whats-next"><a class="heading-anchor" href="#whats-next">What’s Next?</a></h2>
<p>Now that we have the foundational vocabulary down, we can explore how to bring this model into the relational world. In <strong>Part 1</strong>, we will dive straight into <strong>SQL/PGQ in PostgreSQL</strong>: what this new standard brings to the table, how it is implemented under the hood, and its current limitations.</p>
<!-- 👉 **What is your current stack?** Are you running a native graph database, or are you looking to extend your existing relational database? Let me know in the comments below! -->
<hr class="footnotes-sep">
<section class="footnotes">
<ol class="footnotes-list">
<li id="fn1" class="footnote-item"><p><a href="https://neo4j.com/docs/operations-manual/current/database-internals/store-formats/" target="_blank" rel="noopener">Neo4j store formats</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn2" class="footnote-item"><p>Several pictures borrowed from <a href="https://dl.acm.org/doi/10.1145/3604932" target="_blank" rel="noopener">Besta, M. et al. (2023). Demystifying Graph Databases: Analysis and Taxonomy of Data Organization, System Designs, and Graph Queries. <em>ACM Computing Surveys</em>, 56(2), Art. 31.</a> <a href="#fnref2" class="footnote-backref">↩︎</a></p>
</li>
</ol>
</section>
 ]]></content>
			<author>
				<name>Ayoub Kazar</name>
			</author>
    </entry>
</feed>
