SQL vs NoSQL: Choosing a Data Model Under Real Constraints
SQL vs NoSQL decided on real constraints: what relational databases guarantee, the types of nosql databases, when to use nosql over SQL, where each model fails, and the NewSQL middle ground, with the decision table.
The Databases cluster recorded two debts that only this article can pay. Database replication called the data-model decision “the one that changes what replication means in practice”; copies of strongly consistent tables and tunably consistent partitions are different operations wearing the same word. Database sharding noted that data models make sharding easier or harder by design; a model whose unit of data is one key shards naturally, while a model whose unit is a join shards into application-code pain. This article makes both observations concrete, with the decision table the plan reserves for comparison articles at the end.
Relational vs non relational is the real sorting underneath the branding. A relational database stores data in tables with a schema declared up front, and guarantees multi-row transactions (all-or-nothing, isolated, durable) and ad-hoc joins across those tables. The non-relational family (NoSQL, in its loose and contested umbrella sense) stores data in shapes other than the joined table and relaxes at least one of those guarantees to optimize for something else: raw access speed at one key, flexible shapes, write throughput, or relationships. Neither is a better database; they are different contracts, and the badge is the least of it: two stores wearing the same badge can differ more than a SQL/NoSQL pair, so the contract, not the name, is the sorting.
What each model actually guarantees
The relational contract has three clauses. Schema: the shape of the data is declared up front, the database enforces it, and changing it is a deliberate discipline called a migration. Transactions: multi-row, multi-statement work is all-or-nothing (atomic, isolated, durable) so an operation that touches several tables either happens completely or leaves no trace. Joins: questions can be asked across tables after the fact, without predicting them at design time, because the planner composes the answer. The contract’s price runs in the same direction: writes that do not fit the schema fail loudly, and the model assumes the structure it enforces is real.
NoSQL is not one contract but a family of relaxations, and that is the honest way to read the term: each type drops a clause of the relational contract to buy something specific. Dropping the fixed schema buys flexible shapes. Dropping multi-row transactions buys horizontal scale. Dropping joins buys single-access-path speed. The umbrella word hides the choice being made, so the real question in any SQL vs NoSQL decision is never “which is better” but “which clause of the contract can this workload genuinely live without,” because every relaxed clause resurfaces later as application code doing the database’s job.
What the schema actually buys deserves its own paragraph, because it is the part teams surrender last. A declared schema is an enforced invariant: the foreign key means the reference is real, the NOT NULL means the field exists, and the database refuses to become inconsistent on a bad deploy. That enforcement is visible (greppable, documented, reviewable in a migration) instead of implicit, and the relational model’s maturity means the tooling around it, from planners to backups to access control, is the deepest in the industry. None of this says the relational model is always right; it says the guarantee being weighed is real, and a migration away from it should know exactly what it is leaving.
The types of NoSQL databases
The family, sorted by what each type optimizes:
- Key-value, the simplest contract: one key, one opaque value, single-key operations at memory speed. The caching series’ Redis is the archetype; redis caching covers its pattern use, and the model optimizes point access while dropping every relational clause except the key itself.
- Document: self-describing, JSON-shaped documents under one key. The schema moves inside the document, and a whole aggregate (order with lines, profile with settings) loads in one read. The relaxed clauses are joins and cross-document transactions.
- Wide-column: sparse rows grouped into partitions, tuned for sustained write streams at fleet scale. The data model carries its own partition key, repaying the sharding debt this article opened with: data models that shard naturally build the placement into the row itself. Multi-row transactions and ad-hoc joins are the hardest relaxations here.
- Graph: nodes and edges as first-class citizens, answering relationship questions by traversal instead of join. It optimizes whatever is reachable by following edges, and relaxes everything that is not.
- Search, the inverted index as a data model: documents in, relevance-ranked text queries out. The machinery and the when-to-add decision belong to search engines in system design; as a model it optimizes text queries and relaxes transactionality to near-zero.
The types are not interchangeable, and the failure mode is always the same shape: a store used for the wrong access pattern pays the relaxed clause as application code. A document store forced to serve relational queries accumulates joins in the application; a relational database forced to store giant blobs accumulates slow tables: the file tier’s problem, and object storage’s to solve. The rule is the one database indexing taught for columns: the structure follows the access pattern, not the other way around.
The family also composes, which is how most real systems end up looking: polyglot persistence: the relational core beside a cache, a search index, a queue’s state, and a file tier, each chosen for its access pattern. The discipline that keeps the composite honest is owning the synchronization between stores: one authoritative source per datum, explicit pipelines for every derived copy, and a named answer for what happens when a pipeline falls behind. That discipline has its most visible article in search indexing, where the pipeline problem is on display; the file tier’s version of the same rule lands in object storage. The composite’s failure mode is the single store’s failure mode repeated: a store added without its pipeline, drifting silently from the truth.
When to use NoSQL and when not
The honest cases for NoSQL are access-pattern-shaped, and they have a pattern of their own. When reads load whole aggregates by one key (the profile with its settings, the order with its lines) the document model answers in a single read and the runtime join was fiction all along. When the growth plan is measured in shards, models that carry their own partition key make sharding a native operation instead of an invasion. When shapes genuinely vary per tenant or experiment, a schema that moves into the document removes a migration from every change. And when the workload is a sustained write stream, the wide-column family absorbs it on a single strong-contract node’s best day. In each case the model wins because the workload already looks like the model.
The cases against are the mirror image. Multi-entity transactions (money movement, inventory with its order) are the relational contract’s home turf, and doing them by hand across a relaxed model is the saga problem restated. Referential integrity enforced by the application is integrity that stops being enforced the day the application forgets. Ad-hoc analytics and reporting live on joins, and a reporting layer over a join-less model is a second database nobody budgeted. And the most common reason of all (choosing NoSQL to skip schema design) defers the discipline rather than removing it: the schema reappears as implicit assumptions in code, enforced by nothing, discovered by incidents. Every extra store also adds a sync pipeline and a consistency surface, the tax search indexing makes visible when it is added alongside the primary database.
A worked decision shows the clauses in action. Take a store: orders, catalog, sessions, and search. Orders are relational without argument; money movement, inventory decrements, and reporting are the contract’s home turf. The catalog is genuinely debatable: whole aggregates read by ID suit documents, but the relational answer also serves merchandising’s ad-hoc queries, and the honest tiebreaker is which team owns the reporting. Sessions are key-value in every shape that matters (one key, one blob, an expiry) and the caching series implements that tier. Search is text-shaped: relevance ranking the database cannot do at any speed, which earns its own index and its own consistency question. The composite answer (one relational core, one cache, one search index) is not a compromise; it is the model-matches-access-pattern rule applied four times, and if the debatable call goes wrong, the migration cost is the asymmetry the decision table’s section prices next.
Consistency and replication trade-offs
Here is the debt this article owes database replication: what the data model changes about replication itself. In a relational system, replication copies strongly consistent tables; a follower lags, but it serves older rows of a single, ordered truth. In the tunable-consistency corner of the NoSQL family, consistency becomes a dial instead of a property: quorum reads and quorum writes choose how many replicas must agree before the operation succeeds, and the vocabulary (what eventual consistency promises and what a quorum buys) is the CAP theorem and consistency models’ subject. Leaderless replication turns the stale read from an accident into a configuration.
The operational consequences follow the dial. Background convergence (read repair, anti-entropy passes) keeps the copies drifting toward each other, and the application answers the question the database no longer does: can this screen show data that is a moment old? If the honest answer is no (balances, authorizations, stock states) the dial cranks toward strong quorums, and the throughput that motivated the model begins to shrink. The trade is not a bug in either model; it is the same trade this cluster keeps pricing from different angles (consistency against scale) with the data model deciding who pays and when. The mechanics of replication topologies, synchronous versus asynchronous, and lag measurement stay in the replication article; what the model changed is who is allowed to answer the freshness question.
One more price of the tunable dial deserves naming: conflicts. When replicas accept writes independently and converge in the background, two divergent copies must eventually be merged, and the merge policy is application design; last-write-wins is the default and loses data silently, while purpose-built merge logic or conflict-free replicated data types trade that silence for structure. The relational model never asks the question; the tunable models ask it on every concurrent edit, and the design review for a relaxed-consistency system is where the answer has to live before production writes it instead.
The decision table
Comparison articles in this cluster carry one table, on the dimensions the editorial plan fixes for them (architecture, consistency, complexity, failure behavior, and best fit) with the relational side and the document side as its two poles, because that is the decision most systems actually face:
| Dimension | Relational (SQL) | Document NoSQL |
|---|---|---|
| Architecture | Joined tables under a declared schema | Self-describing aggregates, one key each |
| Consistency | Strong by default (transactions, one ordered truth | Tunable) quorums to eventual, a dial per system |
| Complexity | Paid up front, in the schema and its migrations | Paid late, in application code (joins, integrity, resync |
| Failure behavior | Loud) constraints refuse the bad write | Quiet; shapes drift until code notices |
| Best fit | Multi-entity transactions, ad-hoc queries, reporting | Aggregate reads, key-shaped access, horizontal growth |
The decision also has a middle term now, and the plan reserves it for a section rather than an article: NewSQL; distributed engines that keep SQL’s full contract, schema and transactions and joins, while sharding the data underneath. Google’s Spanner demonstrated the pattern; the engines that followed it made distributed SQL an installable choice. What NewSQL buys is the union of the two columns above, the relational contract at horizontal scale. What it does not do is make the decision free: the operational weight of a distributed system arrives with the engine, and a workload that fits one node never needed the question answered.
The table also hides a practical asymmetry worth stating before the FAQ: the decision is expensive to reverse. Data migrations between models are among the slowest, riskiest projects a team can schedule (every record reshaped, every client rewired, both stores kept in sync through the transition) so the honest method is to decide from the workload’s shape at scale, not from the demo’s shape at zero: prototype with whichever model is fastest to stand up, decide with the contract the system will need in its third year, and treat the choice as architecture rather than installation.
FAQ
What is the difference between SQL and NoSQL?
SQL databases commit to a contract (declared schema, multi-row transactions, ad-hoc joins) and enforce it. NoSQL is a family of models that each relax a clause of that contract to optimize for something else: point speed, flexible shapes, write throughput, or relationships. The difference is not quality but which guarantees your workload can live without, and the sorting that matters happens at the clause level: schema, transactions, joins.
When should you use NoSQL?
When the workload already looks like the model: whole aggregates read by one key, growth plans measured in shards with the partition key inside the data, shapes that genuinely vary per tenant, or sustained write streams that outpace one strong-contract node. Not when the goal is skipping schema design; that defers the discipline into code instead of removing it.
What are the main types of NoSQL databases?
Key-value (one key, one value, point access; Redis the archetype), document (JSON-shaped aggregates under keys), wide-column (sparse rows in partitions, built for write streams), graph (nodes and edges, traversal instead of joins), and search (the inverted index, relevance-ranked text queries). Each optimizes one access pattern and relaxes the rest.
Is NoSQL faster than SQL?
Faster for the access pattern it optimizes; a single-key read in a key-value store is hard to beat. Slower the moment the workload needs what the model relaxed: the join done in application code, the transaction simulated by saga machinery, the integrity checked by hand. Speed is a property of the match between model and access pattern, not of the badge on the database.
What is NewSQL?
Distributed engines that keep SQL’s contract (schema, ACID transactions, joins) while sharding the data across nodes, Spanner’s pattern made installable. It buys the relational contract at horizontal scale, at the operational price of a distributed system; it does not remove the decision, it widens the middle of it.
Can you use SQL and NoSQL together?
Yes, most systems at any scale do. The relational core holds what needs the contract; key-value, document, search, or file stores hold what their access patterns favor; and explicit pipelines keep the derived stores in sync with the one authoritative source. The composite is a design discipline (ownership of every sync path) not a loophole out of the decision.
Related articles
- Next read: blob and object storage, where data goes when it outgrows any database: the file tier, where objects are their own unit of copying.
- database replication; the mechanics underneath what the data model changes about copying.
- database sharding: the fleet machinery either way, and the models that make it native.
- database indexing; the read lever under whichever model wins. The model debate decides where data lives; the index decides how quickly it is found, and no model wins without one.
- CAP theorem and consistency models, the vocabulary behind the tunable dial. Every “eventually” inside a NoSQL guarantee is a consistency model wearing its own name, worth reading before trusting the dial.
- search engines in system design, the search model: when text queries earn a store of their own. Document stores and search engines meet the same text problem from opposite sides of the stack.