Skip to content

Choose relational, document and key-value models

11 min reading

Compare models against the same declared access patterns

Page details

System Design · Store and find data

11 min reading · 24 min with practice

Sources

Published · Last edited:

Prerequisite: Start a data design with access patterns. For basics, use the independent System Design foundations.

More
20px

Hypothetical scenario. Dev proposes a document per product, while Priya points out that prices vary by market. Maya asks both to walk through the category read and the same price change. Neither proposal wins merely because its name resembles the application’s objects.

Dev: “Gathering a product together looks convenient for the page.”

Priya: “Where will that convenience put the work when its price changes?”

Compare three representations against the access sheet from page 11. Trace where relationships are assembled and which values are copied. Keep the required ordering, market and freshness evidence constant so the comparison exposes consequences rather than database stereotypes.

Can each model answer the same question?

Keep five visits per second in the selected busy interval. Each visit makes one promotion read, one category read and one detail read. Listings return up to twenty product appearances each; detail returns one. The earlier 205 appearances per second remains a result-cardinality estimate, not a count of storage operations.

All alternatives must select the requested market and currency, preserve the chosen ordering and provide the evidence needed for price age. Comparing an indexed relational query with a key-value store asked to scan its whole dataset would compare access paths as well as models. Make both differences explicit.

A data model organizes identity, relationships and values. A storage engine implements physical persistence and access structures. A product may support several modeling styles. PostgreSQL can represent structured relational records and other forms of values; a document database still has schemas and constraints even where different documents need not have identical fields.

A relational baseline makes relationships explicit

Northwind can separate products, applicable prices, category memberships and promotion memberships. Keys identify records; relationships connect them. A category query selects membership, joins the relevant product and price data and returns an ordered bounded result. A detail query uses a product identity and the applicable price identity.

This arrangement avoids copying the current price into every category membership. It introduces query planning and index decisions, which the next lesson will examine. Relational representation does not mean every query scans every table, and a join is not automatically too slow. Execution depends on access structures, selectivity, data distribution and resource conditions.

PostgreSQL’s constraint mechanisms can enforce declared key and reference rules. Stronger multi-record update requirements need an appropriate transaction and isolation design; the later correctness module develops those mechanisms. Naming a relational database alone does not settle every concurrency requirement.

Compare the same selected price in three representations

Hypothetical scenario. Represent Q7 in relational tables, a product document and direct key-value entries. Keep UK/GBP selection, source revision and price-evidence time identical. A fair comparison changes storage representation without quietly weakening the result contract.

Compare the same selected price in three representations — selected design evidence
RepresentationIllustrative shapeUpdate boundary to verify
RelationalProduct(Q7); Price(Q7, UK, rev12)Transaction covers required rows
DocumentQ7 with embedded UK price rev12Selected document update
Key-valueprice:Q7:UK → revision 12Direct value plus separate indexes
The stale category copy exposes repair work that a convenient embedded read can hide.The stale category copy exposes repair work that a convenient embedded read can hide. Source price rev12 to Product document: write aggregate; Source price rev12 to Category copy rev11: repair older projection.Source price rev12Product documentCategory copyrev11write aggregaterepair older projection
The stale category copy exposes repair work that a convenient embedded read can hide. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

A relational design may join product and market-price rows. A document may embed market prices inside one product aggregate. A key-value design may use a direct product-market key and maintain separate category membership. These choices alter read assembly and update fan-out; none of their family names alone promises a transaction spanning arbitrary records.

If a category page embeds the selected price, its copy needs an update and repair contract. A source revision on each copy lets a reconciler distinguish older materialization from current evidence. It still needs a discoverable list or scan of expected copies. Schema evolution also has a cost: readers must interpret old and new stored forms during migration, and rollback must understand anything the new writer has already persisted.

A document baseline gathers a chosen aggregate

A product document can group display fields and a bounded set of applicable prices. This can suit a detail read that usually needs those fields together. Category selection still needs a supported access path, and promotion membership may either be embedded, referenced or represented separately. The document boundary is a design choice, not a fact dictated by the frontend card.

MongoDB’s data-modeling guide discusses organizing related data around application access. That gives Northwind a useful question: which data is read and changed together? It does not imply that every relationship should be embedded or that duplicated prices will maintain themselves.

Representations move assembly and maintenance workRelational records connect membership to product and price at query time. A document groups chosen product fields. A key-value read representation stores a preassembled category page. Faster reuse can move work into rebuilding or updating that representation.RelationalMembershipProduct + priceQuery assemblyDocumentProduct aggregateChosen fieldsBoundary choiceKey-valueCategory page keyStored responseUpdate maintenance
Every model must pay for required relationships somewhere.

A key-value baseline needs known retrieval identities

A key-value interface retrieves a value through a key. Northwind could store a serialized detail representation under a product/market/currency/version key. It could also store a preassembled category page under a category/version/page key. That makes the read identity simple while introducing a job to build and refresh those values.

Redis strings provide a concrete example of values accessed through keys. This observation is about an interface, not a recommendation to adopt a particular durability or deployment configuration. A fast key lookup says nothing by itself about how a category membership change reaches the stored page.

If a value contains only product identifiers, reading it can still require subsequent product and price retrieval. If it contains full display data, a price change can require updating multiple copied representations. This choice trades read-time assembly against write-time maintenance; neither disappears because the API looks simple.

Count the consequence of duplication

Hypothetical worked example. Choose a product appearing in three category pages and two promotion pages. If every page embeds its current price, there are 3 + 2 = 5 copied page representations to maintain when that price changes. If a separate detail value also embeds it, the count becomes 5 + 1 = 6.

Choose two price changes per second for this illustrative maintenance workload. Updating all six affected values once per change produces 2 × 6 = 12 value updates per second before retries or rebuild overhead. This is a selected fan-out count, not a measured write rate or a claim that every key-value design requires six writes.

If those pages instead retain only product identities and read one authoritative price representation, the number of copied price fields falls. The read path must then assemble prices, perhaps in a batch. Compare that additional work against the earlier latency and result-size contract. A preassembled page is useful only if its refresh delay remains compatible with the sixty-second evidence-age limit.

Do not assign guarantees by family name

Document representation does not imply the absence of transactions. Relational representation does not imply that every deployment reads the newest committed state from every replica. Key-value representation does not imply that the application has no schema. State the selected product’s actual operation and deployment contract when those details matter.

Northwind’s immediate requirement is small enough to compare the representations without inventing a scale emergency. Operational familiarity, available maintenance capacity and future query needs also matter. A theoretically efficient representation that the team cannot observe or safely change is not automatically the better choice.

When convenient read values diverge

Hypothetical failure scenario. A price change updates the detail value and one category page, but another category rebuild fails. Visitors see different prices depending on the entry path. Every lookup succeeds; the stored read representations disagree because maintenance was treated as incidental work.

Possible revisions include reading a canonical price, tracking representation versions and rebuild completion, or changing the acceptable consistency contract. Do not quietly weaken the original promise. If asynchronous maintenance is selected, its lag, recovery and eligible-serving behavior become part of the design that later queue and consistency lessons must explain.

Choose the first model and name its exit condition

For this hypothetical stage, Northwind starts with relational product, price and membership records because the declared relationships and change rules are explicit and the required queries are known. This is a teaching decision, not proof that a document alternative would fail. Keep formatting local and retain the public representation contract from the request module.

Reconsider a separate read representation if measured query work or a concrete independent serving need justifies its maintenance burden. The next page examines the indexes needed by the chosen relational baseline. That is the next missing mechanism, rather than another comparison of database logos.

Challenge the proposed mechanism

A key-value design supports a conditional transaction over the needed keys. Must it be rejected because it is not relational?

Reveal the design reasoning

No. Evaluate the actual conditional and transactional contract, key placement and failure behavior. Conversely, a relational label does not make independent service databases one transaction. Compare the mechanism against the same invariant.

Decision and reconsideration: Choose the simplest representation for current access and change scope. Record a migration trigger tied to measured fan-out or transaction needs.

Keep the comparison fair

  1. A stored category page returns with one key lookup. Has all relationship work disappeared?

    Find when the work moved

    No. The page had to be assembled and must remain eligible as products, prices and membership change. A short read path can move work into maintenance and recovery.

  2. Two changes per second affect six copied values each. What selected maintenance demand follows?

    Multiply fan-out by change rate

    Twelve value updates per second before retries and overhead. This count depends on the selected embedding pattern; a representation holding identifiers instead may have a different cost.

  3. Does choosing relational storage eliminate the need to define consistency?

    Inspect the actual operations and deployment

    No. Replica reads, concurrent transactions and application composition still need explicit contracts. A model family is not a complete guarantee about every observation.

Choosing a representation does not finish the access path. Page 13 examines an index: the work it can avoid on reads and the costs it adds when records change.

Northwind decision log

Start with explicit relational identities and memberships for the declared query set.
Compare alternatives using the same reads, writes and freshness requirements.
Require measured benefit and a maintenance contract before adding copied read representations.

Go deeper: aggregates and change