Skip to content

Part 1 · Blueprint 04

SQL vs. NoSQL vs. NewSQL Storage Engines

15 min reading · Sources · Editorial review pending

A product label does not specify transaction boundaries or read observations.

More
20px
Reading list
Page details

Published date · Last edited:

Draft edition. Editorial review and supplementary reading recommendations are still being completed.

Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: Back-of-Envelope Capacity Estimation.

Sixty-second mental model

Problem: A product label does not specify transaction boundaries or read observations.

Use: Choose from actual access patterns and invariant ownership.

Design boundary: Choose storage from required transactions and access patterns. SQL and NoSQL are families, not automatic answers about consistency or scale. Start by naming records that must change atomically and the queries that must remain efficient.

Layer 1 · Intuition

Hypothetical scenario: Northwind is designing storage selection. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one record means and which component owns the data invariant.

Think of a library separating catalog cards and shelves. Separate the requester from data invariant, then identify the retained evidence needed after failure.

Authority
The entitled state owner.
Invariant
A rule preserved across concurrency and failures.
ACID
Atomicity, consistency, isolation and durability: transaction properties whose exact semantics depend on the system. Analogy: Rules for completing and preserving a coordinated exchange.
Denormalization
Duplicating or precombining data to serve selected reads more directly. Analogy: Printing the delivery address on the dispatch sheet for convenience.
Foreign key
A relational constraint referencing a key in another or the same table. Analogy: A form that must refer to an existing customer file.
Normalization
Organizing relational data to reduce specified redundancy and update anomalies. Analogy: Keeping an address once and referencing it from many forms.
Primary key
A database key uniquely identifying a row. Analogy: The unique file number on a customer record.

Architecture and worked reasoning

Design boundary: Choose storage from required transactions and access patterns. SQL and NoSQL are families, not automatic answers about consistency or scale. Start by naming records that must change atomically and the queries that must remain efficient.

Responsibilities on the request path

Storage selection: responsibilities and request directionChoose storage from required transactions and access patterns. SQL and NoSQL are families, not automatic answers about consistency or scale. Start by naming records that must change atomically and the queries that must remain efficient.Checkout APIInventory transactionOrder recordsRead projection
Choose storage from required transactions and access patterns. SQL and NoSQL are families, not automatic answers about consistency or scale. Start by naming records that must change atomically and the queries that must remain efficient.

Workload and limiting resource

Hypothetical workload: 200 orders/s and four indexed row changes/order yield 800 logical row changes/s before index maintenance and replication. Retaining 200 × 86,400 = 17,280,000 orders/day at 500 bytes/order is 8.64 GB/day in decimal units, excluding indexes and copies. A convenient document shape does not remove those write costs.

Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.

Mutation or publication path

Storage selection: mutation boundaryInsert an order and reserve stock under the chosen transaction boundary. Then: Commit before promising the reservation to the caller. Then: Publish read projections after commitment through a recoverable mechanism.Step 1
Insert an order and reserve stock under the chosen transaction boundary.
Step 2
Commit before promising the reservation to the caller.
Step 3
Publish read projections after commitment through a recoverable mechanism.
Insert an order and reserve stock under the chosen transaction boundary. Then: Commit before promising the reservation to the caller. Then: Publish read projections after commitment through a recoverable mechanism.
  1. Insert an order and reserve stock under the chosen transaction boundary.
  2. Commit before promising the reservation to the caller.
  3. Publish read projections after commitment through a recoverable mechanism.

Observation and recovery path

Storage selection: observation boundaryRead an order by its identity and authorized owner. Then: Query recent orders through an explicit ordered index. Then: Use a projection only with a declared freshness contract.Step 1
Read an order by its identity and authorized owner.
Step 2
Query recent orders through an explicit ordered index.
Step 3
Use a projection only with a declared freshness contract.
Read an order by its identity and authorized owner. Then: Query recent orders through an explicit ordered index. Then: Use a projection only with a declared freshness contract.
  1. Read an order by its identity and authorized owner.
  2. Query recent orders through an explicit ordered index.
  3. Use a projection only with a declared freshness contract.

Failure that changes the decision

Hypothetical scenario: A read projection shows inventory that has already been reserved. The checkout authority must recheck availability; a fast read model must not become an independent allocator.

Attempt this decision before reading the explanation

Can a key-value database replace a multi-row reservation transaction without changing the design?

Only if the invariant fits its supported atomic boundary or the application deliberately changes its allocation protocol. Choosing a product category does not establish the needed transaction semantics.

Supporting mechanism analysis

Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.

Hypothetical scenario. At Northwind, Dev must keep orders, catalogue entries and policy revisions consistent with their access patterns.

In short. Choose storage from queries and transaction boundaries. Give orders an authoritative transactional representation.

Hypothetical scenario. The catalogue now accepts reservations. A reader can browse a seller's item, reserve a quantity and later cancel. The service must avoid promising more units than remain available, and the reservation must identify which seller and item it concerns.

Choosing storage begins with those obligations and the operations that enforce them. It does not begin with a contest between a relational database and a document database. The useful questions are which facts belong together, which changes must be accepted together, and how each reader finds the state it needs.

A table, document, key-value entry or graph edge describes a representation. It does not, by its name alone, establish transaction scope, query cost, durability, consistency or failure behavior. Those are properties of an implementation, configuration and operation.

Likewise, “schema flexible” does not mean “without a schema.” If an application expects an item identifier, a price and a seller reference, that expectation is a contract even when a database permits other shapes. Decide how missing fields, incompatible versions and invalid values are rejected or migrated.

Start with an explicit rule such as “a completed reservation cannot make available stock negative,” then locate the operation that enforces it. Checking a value in one application request and writing a new value later can introduce a race. An application-level check is not automatically an atomic database condition.

Give durable entities stable identities: a seller, an item and a reservation. Their relationships describe ownership and the operation being requested. A rendered item page is a view assembled from those facts; it need not be the only stored representation.

Normalized relationships keep shared facts in an authoritative location. Embedding or denormalizing can make a common read convenient, but a shared fact may then have multiple copies. That trade changes update and recovery work; it is not a moral preference for one representation.

PostgreSQL's constraint documentation illustrates concrete mechanisms for required values, uniqueness and relationships. Their exact semantics matter: a check that can accept a null expression is not equivalent to requiring a non-null value. Verify the mechanism used for each invariant rather than assuming a label covers it.

Northwind's catalogue and checkout ask different questions of their data. A product description can tolerate a declared delay in a derived search view. A stock reservation must preserve a rule about how much inventory remains available. Postgres tables, document records and key-value entries are representations; the important decision is which component can enforce each rule while requests overlap.

Consider a hypothetical stock row with twelve units available. Two buyers each request seven units. Independent reads allow both buyers to observe twelve, even though 7 + 7 = 14 exceeds stock by two. The accepted transition must combine the availability condition and the decrement under an appropriate concurrency contract. Merely putting the same values in one JSON document does not establish that contract. Nor does distributing the order across several services improve the invariant by itself.

A relational model makes references and uniqueness rules visible, while a document model can keep frequently retrieved fields together. Both still need a declared authority for corrections. If the seller address appears in fifty derived product views, one address edit creates fifty projection updates in this toy example. Those updates are a propagation workload, not fifty independent authoritative addresses. Attach a source version and decide what the reader sees while updates are incomplete.

The access pattern then guides physical choices. List the writes that must commit together, the reads that can use an older view, and the operations that cross stores. A confirmed transaction abort permits a different recovery path from a lost response after an uncertain commit. Choosing a database family before writing those distinctions down hides the hardest part of the design behind a product label.

Hypothetical scenario. Choose one million items and ten thousand sellers. Each seller profile has exactly 512 bytes of selected text. Embedding a full profile in every item stores 1,000,000 × 512 = 512,000,000 bytes = 512 decimal MB of that text.

Storing one profile per seller instead uses 10,000 × 512 = 5,120,000 bytes. A chosen eight-byte seller reference in each item adds 1,000,000 × 8 = 8,000,000 bytes. Together these payloads occupy 13,120,000 bytes = 13.12 MB. The difference is 512 − 13.12 = 498.88 MB of modeled payload, excluding row/document metadata, indexes, compression, replicas and other fields.

This does not prove the normalized read is cheaper. It may need another lookup or a join. The model makes the duplication cost visible so that it can be weighed against actual read patterns, update frequency and resource behavior. Do not translate this payload comparison directly into a database bill.

Now choose an item with seven available units. Two requests each attempt to reserve five. If both first read seven and independently compute 7 − 5 = 2, both may write two and report success under an unsafe read-then-write design. Ten units were promised from seven: an excess of 10 − 7 = 3, even though the stored counter never became negative.

A suitable atomic operation must test sufficient remaining stock while applying the decrement, and the reservation record must share the appropriate acceptance boundary. In the chosen scenario, one five-unit reservation can succeed, leaving two; the other must fail or choose a different declared outcome. The exact transaction, conditional-write or concurrency-control mechanism depends on the datastore contract.

Transactions group state changes, but isolation behavior is not identical across systems or isolation levels. PostgreSQL's transaction-isolation documentation explains its snapshots and concurrency behavior. Use that concrete contract when evaluating a PostgreSQL design; do not generalize a product's default to every transactional store.

For the reservation, decide whether inventory decrement and reservation creation must succeed together. If a single database can enforce the needed boundary, separating the operation across services may add coordination work without solving a current problem. A business requirement, ownership boundary or scale constraint should justify that extra boundary.

Layer 3 · Internals

Trade-offs and limits

ApproachProvidesRequires
Relational transaction boundaryCan enforce declared multi-record invariants together.Schema, contention and placement constrain the write path.
Document or key-oriented aggregateCan align storage with a bounded access pattern.Cross-aggregate invariants still require an explicit enforcement strategy.

Recovery decision

Hypothetical scenario: A read projection shows inventory that has already been reserved. The checkout authority must recheck availability; a fast read model must not become an independent allocator.

Only if the invariant fits its supported atomic boundary or the application deliberately changes its allocation protocol. Choosing a product category does not establish the needed transaction semantics.

Write your design before revealing the review

Can a key-value database replace a multi-row reservation transaction without changing the design?

Evidence you can explain in your own design

Drafts and self-review are stored only in this browser. They are separate from reading completion.

Compare your decision

Only if the invariant fits its supported atomic boundary or the application deliberately changes its allocation protocol. Choosing a product category does not establish the needed transaction semantics.

A read projection shows inventory that has already been reserved. The checkout authority must recheck availability; a fast read model must not become an independent allocator.

Check your understanding

Can a key-value database replace a multi-row reservation transaction without changing the design?

Only if the invariant fits its supported atomic boundary or the application deliberately changes its allocation protocol. Choosing a product category does not establish the needed transaction semantics.

How would you recover from this failure: A read projection shows inventory that has already been reserved. The checkout authority must recheck availability; a fast read model must not become an independent allocator.

Start with the exact boundary that failed. Insert an order and reserve stock under the chosen transaction boundary. Commit before promising the reservation to the caller. Publish read projections after commitment through a recoverable mechanism. Then recover evidence through the observation path: Read an order by its identity and authorized owner. Query recent orders through an explicit ordered index. Use a projection only with a declared freshness contract. Preserve the distinction between a confirmed state change and an unavailable response.

Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?

Hypothetical workload: 200 orders/s and four indexed row changes/order yield 800 logical row changes/s before index maintenance and replication. Retaining 200 × 86,400 = 17,280,000 orders/day at 500 bytes/order is 8.64 GB/day in decimal units, excluding indexes and copies. A convenient document shape does not remove those write costs. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Choose storage from required transactions and access patterns. SQL and NoSQL are families, not automatic answers about consistency or scale. Start by naming records that must change atomically and the queries that must remain efficient.

Which component in this topology could be removed from a smaller first deployment?

Checkout API, Inventory transaction, Order records, Read projection name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Insert an order and reserve stock under the chosen transaction boundary.

What evidence must a caller have before relying on the observation path?

Read an order by its identity and authorized owner. Query recent orders through an explicit ordered index. Use a projection only with a declared freshness contract. Only if the invariant fits its supported atomic boundary or the application deliberately changes its allocation protocol. Choosing a product category does not establish the needed transaction semantics.

45-minute interview rubric

  1. 00–05: scope record and data invariant.
  2. 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
  3. 12–28: draw data invariant, numbered writes and reads.
  4. 28–40: challenge recovery: Choose from actual access patterns and invariant ownership.
  5. 40–45: defend record_id placement, observations and remaining assumptions.

Go deeper

Decision log

Choose from actual access patterns and invariant ownership.

Preserve record identity and data invariant ownership.

Revisit changed workload, observations or recovery objectives.