Q21 · How do you pick between relational vs document database?

Back to 24 Architecture Questions.

The question is not a feature-list comparison. The axis it turns on: which access patterns and invariants you already know, and which queries are still unknown. A database is a bet on what you know at design time: relational bets you know the invariants and want them enforced; document bets you know the access unit and that the shape will drift.

The signal table

Signal Points to
Invariants are known and load-bearing (balances, references, “every order has items”) Relational: the database enforces them, in one place
Future queries are unknown (reporting, exploration, ad-hoc) Relational: SQL explores; documents force you to predict access patterns at design time
The access unit is one aggregate (fetch the whole order, never half of it) Document: one fetch, no joins
The shape varies per record and drifts (content, catalogs, per-tenant payloads) Document: shape lives with the record, not in a migration
Many-to-many relations dominate the model Relational: document references turn every join into application code
Shape evolution must be explicit and reviewed Relational: migrations hurt on purpose, and the history is written down

What the answer should contain

Invariants are the first question. Money, references, and aggregates that must hold: a relational database enforces them at the only place every writer passes through. In a document store, “schema-on-read” really means the schema moves into every reader, with no constraint anywhere: three services, three subtly different assumptions, drift by record.

Unknown queries are the second question. Relational plus SQL is an exploration tool: ask a question you did not anticipate at design time. Document stores require predicting the access pattern up front and denormalizing for it; the first unanticipated query becomes a rebuild. If the domain is young and the questions are still forming, that weighs relational regardless of shape flexibility.

The aggregate test. If the application’s unit of work is “load this whole thing, save this whole thing”, documents fit naturally. If the unit of work is “relate these things across boundaries”, relations fit naturally. Matching the storage unit to the work unit removes a whole class of mapping code.

The hybrid is the honest default. A relational core with JSON columns for the loose shapes, a search engine beside it for the query shapes neither store answers well. Most real systems are polyglot per query class, not per fashion; the modern relational engines make the core-plus-blobs option cover a surprising share of both worlds.

Migrations are part of the price. Relational: explicit, painful, planned in steps (expand, migrate, contract). Document: deferred, and the debt lands in every reader that must now tolerate five shapes of the same record. Deferred schema debt compounds faster than migration pain.

Ideas worth mentioning out loud

Follow-ups to expect

Red flags in an answer

Sources