Programming
We provide developers and engineers the guides and tutorials they...
Search
We provide developers and engineers the guides and tutorials they...
Content is king. It's not just about how you're going to write, b...
Looking for an engaging connection with thousands of other people...
SQL vs NoSQL without the hype: relational, document, key-value, wide-column and graph databases compared on schema, scaling, transactions and queries.
Quick answer: SQL (relational) databases store data in tables with a fixed schema, link tables with joins, and offer strong transactional guarantees. NoSQL is an umbrella term for databases that drop one or more of those features, usually to gain flexible data shapes or easier scaling across many machines. Choose a relational database by default: it handles most workloads and keeps your options open. Choose a NoSQL database when you have a specific need it serves better, such as huge write volumes, a simple key-based access pattern at massive scale, or data that is naturally a graph or a nested document.
A relational database such as PostgreSQL, MySQL, SQL Server or SQLite organises data into tables of rows and columns.
The big strength is flexibility of queries. You model the data once and can ask new questions later.
NoSQL is not one thing. It is at least four families:
| Type | Data model | Good for | Examples |
|---|---|---|---|
| Key-value | A key maps to an opaque value | Caching, sessions, simple lookups at huge scale | Redis, DynamoDB, Memcached |
| Document | Keys map to JSON-like documents | Content, catalogues, user profiles, varied records | MongoDB, Couchbase, Firestore |
| Wide-column | Rows with a partition key and many flexible columns | Time series, event logs, very high write volume | Cassandra, HBase, ScyllaDB |
| Graph | Nodes and relationships | Social networks, recommendations, fraud rings | Neo4j, Amazon Neptune |
Search engines such as Elasticsearch, time-series databases and vector databases are often grouped here too.
In the 2000s, large web companies hit the limits of running a relational database on a single machine. Scaling up to a bigger server has a ceiling, and spreading a relational database across many servers by hand was painful.
Two papers shaped what followed: Google's Bigtable and Amazon's Dynamo. Both gave up joins and general transactions in exchange for a design that spreads data across many machines and keeps working when some fail. Open-source systems such as Cassandra, HBase and MongoDB followed. More on that history in why big tech companies build their own databases.
| Relational | Document / NoSQL |
|---|---|
| Schema enforced by the database on write | Schema enforced by your application, if at all |
| Changing structure needs a migration | New fields can appear at any time |
| Bad data is rejected | Bad data may be stored silently |
"Schemaless" is misleading. Your code still expects a certain shape; the schema has just moved from the database into the application. That flexibility is useful early on and for truly varied data, and a source of bugs later.
Relational databases join tables at read time. Document and key-value stores have limited or no joins, so you denormalise: store related data together, duplicated where needed.
This leads to the key design difference:
If your access patterns are known and stable, the NoSQL approach is fast. If they change, you may need to restructure your data.
Relational databases traditionally scale vertically (a bigger machine) plus read replicas. Many NoSQL databases are built to scale horizontally: data is partitioned automatically across many nodes by key. See sharding explained.
Many distributed NoSQL systems default to eventual consistency: replicas may briefly disagree after a write. That improves availability and latency, and pushes complexity to the application. See the CAP theorem explained.
The clean split of fifteen years ago no longer holds:
JSONB type and MySQL's JSON support let you mix flexible documents with relational tables, with indexes.So the real questions are about data model, access patterns and operational needs, not about a label.
Ask these in order:
| Use case | Typical fit |
|---|---|
| Line-of-business app, e-commerce, SaaS product | Relational |
| Financial ledger | Relational or distributed SQL |
| Cache, session store, rate limiting | Key-value (Redis) |
| Content with varied structure | Document, or relational with JSON columns |
| Metrics, IoT, event logs at very high volume | Wide-column or time-series |
| Social graph, recommendations | Graph |
| Full-text search | Search engine alongside a primary database |
Most real systems combine databases, each doing what it is best at: PostgreSQL as the source of truth, Redis as a cache, Elasticsearch for search, perhaps a warehouse for analytics. This is sometimes called polyglot persistence. The cost is keeping them in sync, so add each one for a clear reason.
Neither is better in general. Relational databases are the safer default; NoSQL databases are better for particular workloads.
Originally "no SQL", later softened to "not only SQL". It simply means non-relational.
Yes, and many systems do: a relational database as the system of record, with a key-value cache or search engine alongside.
If you are unsure, PostgreSQL. It covers relational needs and stores JSON documents well. Choose a document database when your data truly is document-shaped and your access patterns are clear.
"SQL vs NoSQL" is really a question of which trade-offs fit your data and queries. Relational databases give you flexible queries and strong guarantees. NoSQL databases give you specialised data models and built-in horizontal scale, in exchange for designing around your access patterns. Start relational, and add specialised stores when a real need appears.