Skip to main content
Back to Blog

Relational and document databases

Ria opens a relational drawer beside a document cabinet.

Fernando Torres

CEO & Cofounder, Memori · Stanford GSB MSx ’26 ·

Ria opens a relational drawer beside a document cabinet. Instead of declaring one rigid and the other structureless, she shows the constraints, indexes, and access patterns each can support.

Long-term storage keeps records outside active context until an application retrieves them.

Ria places a grid of rows and named attributes on the archive table while Ava points at the heading.
Panel 1 transcript: Ava: "Does relational mean the tables relate to each other?" Ria: "The name comes from a mathematical relation: rows of tuples over named attributes."
Ria adds key, constraint, and join cards to the relational drawer.
Panel 2 transcript: Ria: "Schemas, keys, constraints, transactions, and joins make important rules explicit."
A nested document record opens to show an address object and a list of projects.
Panel 3 transcript: Ria: "A document database stores a nested record as a unit. Its shape can evolve without being unstructured."
Ria stamps the document with validation and secondary-index cards.
Panel 4 transcript: Ava: "So documents can validate fields and index them too." Ria: "Yes. Flexible does not mean rule-free or scan-everything."
A decision sheet compares transactions, constraints, nesting, query shape, and change rate without a winner badge.
Panel 5 transcript: Ria: "Choose from the data model, guarantees, access patterns, and operating cost."

Problem: Ava sees rows in one cabinet and nested records in another, but the old grid-versus-unstructured story hides the guarantees and overlap that matter.

Resolution: The reader learns that relational systems organize relations with schemas, constraints, and joins, while document systems store nested records and can still validate schemas and use secondary indexes.

Relational and document capabilities. Show two capability columns with an overlap band. Relational includes relations, keys, joins, and transactions.

Relational refers to mathematical relations, not merely relationships between tables. Document records can be structured, validated, and indexed. The operations and guarantees decide the fit.

What relational means

In the relational model, a relation is a set of tuples over attributes, commonly presented as a table of rows and columns. Tables can reference one another through keys and joins, but those references are not where the model gets its name. Schemas and constraints let a database enforce important invariants.

Suppose an approval record must reference an existing project and one authorized owner. Foreign keys and uniqueness constraints can reject invalid states before application code reads them. A transaction can update the approval and its audit row together, so a failure does not leave half of the change behind.

Those guarantees are not automatic merely because data appears in a grid. The schema has to express them, and the application has to use transactions correctly. The useful question is which invariants the database must protect under concurrent writes, retries, and failures.

Documents still have structure

A document database stores a nested record as a unit, often close to the shape an application reads and writes. Records may vary, but many document systems support schema validation and secondary indexes. A JSON document is structured or semi-structured data, not automatically an unstructured blob.

A project document might contain its title, milestones, participants, and settings in one nested record. Reading that aggregate can be direct because the related fields travel together. Updating one deeply shared fact across thousands of duplicated documents can be harder, so the shape should follow ownership and change patterns rather than visual convenience.

Flexible shape also needs governance. Optional fields, versioned schemas, and validation rules can support gradual evolution, but unrestricted variation can push errors into every reader. Document storage changes where structure is enforced. It does not remove the need to define structure.

Use operational evidence

Relational systems can store JSON, and document systems can run structured queries. The useful distinction is how each design handles joins, nested aggregates, transactions, constraints, schema evolution, and operational scale. A design can also use either model without adding a separate database product.

Start with representative operations. If the critical write touches several records that must change together, test that path under concurrency. If the critical read needs one nested aggregate, measure that shape and its update cost. Include backup, migration, permission enforcement, and failure recovery instead of comparing only one query screenshot.

The answer can change as the product changes. A document-shaped prototype may later need stronger cross-record constraints. A relational system may add JSON for a flexible edge. Treat the model as an engineering choice that can evolve, not an identity the application must defend forever.

Document the reason for the choice and the evidence that would trigger another review. That turns migration from an admission of failure into a planned response to changed operating needs.

Glossary

Relational databases
Databases grounded in relations of tuples and attributes, with explicit schemas, constraints, keys, joins, and transactions. | Office analogy: Ria uses grid drawers with enforced labels and cross-references.
Document databases
Databases organized around self-contained nested records that can still be validated, indexed, and queried. | Office analogy: Ria files one structured folder for each aggregate.
Structured and semi-structured data
Data with machine-readable fields and organization, even when individual records do not all share one rigid shape. | Example: A validated JSON document can contain optional nested fields without becoming unstructured text.
Relation
In the relational model, a set of tuples over named attributes, commonly shown as a table.
Document record
A self-contained nested record, often represented as an object with fields, arrays, and subdocuments.
Secondary index
An additional lookup structure over selected fields. Both relational and document systems can provide one.

Try it yourself

  1. Explain the difference with one example: which part of your data needs strict relationships, and which part benefits from a flexible document shape?
  2. Write down the invariants that storage must enforce before choosing a model.
  3. Test the most important reads and writes, including joins or nested updates, with representative data.

Next episode

Next: combine sparse lexical and dense semantic retrieval, then decide where structured constraints belong.