# Relational, Document, or Graph — Choosing a Data Model

- Published: 2026-10-19
- Updated: 2026-10-21
- Tags: Reading DDIA, Databases, Software Engineering
- URL: https://devtrillo.com/writing/reading-ddia-2-choosing-a-data-model/

Every couple of years a new database shows up and promises to end an old argument.

Should your data live in tables, in documents, or in a graph?[^graph]

The pitch is always the same. The old way was rigid. The new way is flexible. Just switch and your problems go away.

Chapter 2 of DDIA[^ddia] is the calm adult in that room. It walks through the three big data models, shows what each is actually good at, and quietly makes one point over and over.

The right model is the one that fits how your data is shaped and how you read it back. The fashion has nothing to do with it.

## The three models, in one breath

There are three families worth knowing.

**Relational.** Your data lives in tables of rows and columns. Things that relate to each other are linked by keys, and you pull them back together with a join.[^join] This is SQL. It has run the world since the 1980s, and the obituaries written for it keep being wrong.

**Document.** Your data lives in self-contained documents, usually JSON.[^json] A record and most of what belongs to it sit together in one place. This is the model behind MongoDB and friends. It feels natural when your data looks like a tree.

**Graph.** Your data is nodes and the edges between them. This shines when the connections are the point, like a social network or a map of who-knows-what.

The chapter's honest framing is that this is not a fight with a winner. Each model is a good answer to a different question. The trick is knowing which question you are actually asking.

## The mismatch that started it all

Most of us write code in objects and store data in tables.

Those two shapes do not line up. An object holds a list inside it; a table cannot. So you flatten the object across a few tables on the way in, and glue it back together on the way out. The book calls this the impedance mismatch,[^impedance] and a whole industry of tools[^orm] exists just to paper over it.

The document model was born to kill that annoyance. If your data is really one big nested thing, a user with their profile and their settings and their recent orders, you can store it as one document. It comes back in one read. No gluing.

When your data is genuinely tree-shaped, this is lovely.

The problem starts when your data is not a tree.

## The project where I picked wrong

Here is mine.

We were building an app fast. Users, teams, projects, the usual. I reached for a document database because early on it felt frictionless. No migrations[^migrations] to write, no schema to argue about. I could change the shape of a record by just writing a different shape. We shipped quickly and it felt like a good call.

It was a good call. For about four months.

Then the relationships showed up.

A user could belong to many teams. A team had many users. A project could be shared across teams. Permissions cut across all of it. None of that is a tree. All of it is the thing document databases are worst at: many-to-many.[^many-to-many]

**A document tree next to the relationships that showed up.** On the left, data that fits a document: one user with their profile, settings and orders nested underneath, a single tree you can read in one shot. On the right, what the product grew into: users belong to many teams and teams have many users, teams and projects are shared with each other many-to-many, and permissions point at users, teams and projects all at once. There is no single root to store as one document.

So I did what you do. I started storing IDs inside documents and looking up the other side by hand, in application code. I was writing joins. I was just writing them badly, in a language not built for them, without any of the guarantees a real database gives you.

The flexibility I bought at the start, I paid back with interest in the middle.

Kleppmann says this almost to the word: the document model works well for one-to-many and self-contained data, and it works badly the moment your data grows many-to-many connections. I had read that sentence. I just had not believed it until I lived it.

## What I should have asked

The mistake was not picking the document model. For the first version, it was fine.

The mistake was picking it without asking how the data would connect once the product grew up.

Because that is the question underneath the whole chapter: how is my data related, and how will I read it back?

- **One-to-many and mostly self-contained?** A document fits. Store the tree, read it in one shot.
- **Lots of many-to-one, where many records point at the same shared thing?** That is relational. You want to store that thing once and reference it, so a rename fixes it everywhere at once.
- **Many-to-many that keeps growing new kinds of connections?** Lean toward relational, or a graph if the connections are the main event.

Notice what is missing from those questions. None of them mention which database is trending. They are all about the shape of the data and the way you touch it.

## Schema on the way in, or on the way out

One more idea from this chapter earned a permanent spot in my head.

Everyone says document databases are "schemaless." That is a marketing word. Your data always has a schema. The only question is who enforces it, and when.

A relational database checks the shape on write. Nothing gets in that breaks the rules.

A document database checks the shape on read. Anything gets in, and your code figures out what it got when it reads it back.

The book names these schema-on-write and schema-on-read.[^schema] Neither is cheating. Schema-on-read is genuinely nice when records are all different or the shape is still moving. Schema-on-write is genuinely safer when you need everyone to agree on what a record is.

What bit me was not knowing which one I had chosen. "Schemaless" did not mean no schema. It meant the schema now lived, undocumented, in my application code. Every reader had to guess. Some guessed wrong.

## A word on graphs

I have not reached for a graph database in anger yet, so I will keep this honest and short.

Graphs are the right tool when the connections matter more than the records. Social graphs, recommendation networks, fraud rings, anything where you want to ask "how is A connected to B, five hops away." Doing that with joins gets ugly fast. A graph query language is built for exactly that walk.

I have not needed one. But I now know the smell of a problem that would want one, which is the useful part.

## The other quiet lesson: say what, not how

The chapter also contrasts two ways to ask a database for data.

An imperative query is a recipe. Do this, then this, loop over that. A declarative query, like SQL, just describes the result you want and lets the database work out how to get it.

Declarative wins for a reason that outlives any single database. Because you only said what you wanted, the database is free to get faster underneath you, add an index, change the plan, run it in parallel, without you rewriting a thing. You gave it room to improve.

That is a small idea with a long reach, and it is why SQL refused to die.

## One idea I'll actually use

Every post in this series ends with the one thing I am taking with me.

From Chapter 2, it is a question I now ask before I touch a database: **how is this data connected, and how will I read it back?**

Not "which database do I like." Not "what did the last project use." Not "what is everyone posting about."

Just the shape of the data, and the way I will query it.

If it is a self-contained tree, a document is fine. If the same thing gets referenced from everywhere, or the connections keep multiplying, I want tables and real joins, and I want them from the start.

I picked wrong once by skipping that question.

The database was not the problem. Not asking was.

Next in the series: how databases actually store your data on disk, and the least glamorous topic in the book that saved me the most real-world pain.

[^ddia]: Martin Kleppmann, [_Designing Data-Intensive Applications_](https://dataintensive.net/) (O'Reilly, 2017). Chapter 2 covers data models and query languages.

[^json]: JSON is a common text format for storing structured data as nested key-value pairs. It is the same shape you already work with as an object in most programming languages, which is part of why it feels natural to store.

[^migrations]: A migration is a script that changes the shape of your database, like adding a column or a new table, and keeps existing data working under the new shape. Relational databases usually need one for every structural change; document databases let you skip that step, which is convenient right up until it isn't.

[^graph]: A graph here just means data seen as dots and the lines between them. The dots are your records (people, places, things) and the lines are the relationships (follows, owns, knows). It is the same "graph" as a social graph, not the kind with an x and y axis.

[^join]: A join is how a relational database stitches two tables back together. You store users in one table and orders in another, and a join follows the shared key to answer "show me this user's orders" in a single query.

[^impedance]: The "impedance mismatch" is a borrowed electronics term for the friction between how your code holds data (objects, with lists nested inside) and how a relational database stores it (flat tables). The two shapes do not line up cleanly, so you spend effort translating between them.

[^orm]: An ORM (object-relational mapper) is a library that does that translation for you, turning rows from tables into objects in your code and back again. Handy, but it hides the mismatch rather than removing it.

[^many-to-many]: A many-to-many relationship is when records on both sides can link to many on the other. Users belong to many teams, and teams have many users. Document databases handle one-to-many well (one order has many line items) but struggle here, because there is no single tree to store.

[^schema]: Schema-on-write checks that data fits the rules before it is stored, so bad shapes never get in. Schema-on-read stores whatever it is given and sorts out the shape when the data is read back. Same schema either way; the difference is who enforces it and when.
