SQL vs NoSQL: what's the difference?
SQL vs NoSQL compared: how relational and non-relational databases store data, the ACID and BASE trade-offs, and how to choose between them.
On this page
SQL and NoSQL are the two big families of databases, and the choice between them shapes how your application stores, queries, and scales its data. SQL databases store data in tables with a fixed structure, while NoSQL databases use flexible models like documents or key–value pairs. Neither is better in general — each fits different kinds of problems.
What SQL is: the relational language
SQL (Structured Query Language) is the standard language for relational databases, which organize data into tables of rows and columns, like a spreadsheet. SQL was developed at IBM in the early 1970s by Donald D. Chamberlin and Raymond F. Boyce, building on Edgar F. Codd's relational model. It was originally called SEQUEL — the name was changed because SEQUEL was a trademark owned by a British engineering company. Oracle V2, released in June 1979, was one of the first commercially available implementations, and by 1986 ANSI and ISO had adopted "Database Language SQL" as an official standard. The standard has been revised ever since, most recently as SQL:2023.
The defining trait of a relational database is its schema: you define tables, columns, and data types before you insert data, and the database enforces that structure on every row. Because data is spread across related tables, queries can join them on the fly — a classic example is an orders table referring to a customers table by ID. This is also where the object–relational impedance mismatch comes from: mapping between rows in relational tables and objects in your programming language takes extra work.
What NoSQL is: "not only SQL"
NoSQL ("not only SQL" or "non-relational") covers databases that store and retrieve data outside the table model. Instead of rows and columns, these databases use one of several structures:
- Key–value stores — a dictionary of keys and values. Examples: Redis, Amazon DynamoDB.
- Document stores — records stored as documents in JSON-like formats (MongoDB uses BSON), addressed by a unique key. Examples: MongoDB, CouchDB.
- Wide-column stores — tables that can have a different set of columns per row. Examples: Cassandra, HBase.
- Graph databases — data modeled as nodes and relationships. Example: Neo4j.
The term has two histories. Carlo Strozzi used "NoSQL" in 1998 for a relational database without a SQL interface. The modern meaning took shape in early 2009, when Johan Oskarsson, then at Last.fm, used it for an event about open-source distributed non-relational databases. The movement's central ideas: no fixed schema — each record can have different fields — and horizontal scaling across clusters of machines, driven by web companies handling very large data sets.
The trade-offs: ACID vs BASE
Relational databases are built around ACID transactions: atomicity, consistency, isolation, and durability. This is why they dominate banking, accounting, and anywhere a failed half-written transaction is unacceptable.
Many NoSQL systems follow a different philosophy, often summarized as BASE: basically available, soft-state, eventually consistent. The CAP theorem, stated by Eric Brewer (PODC 2000) and proved by Seth Gilbert and Nancy Lynch in 2002, says a distributed data store can provide at most two of three guarantees: consistency, availability, and partition tolerance. ACID-oriented systems lean toward consistency; BASE-oriented systems lean toward availability. Under eventual consistency, a database replica may briefly serve stale data, but if updates stop, all reads eventually return the latest value.
The boundary is blurry, though. MongoDB, a document store, has supported multi-document ACID transactions since version 4.0, released in June 2018. And the reverse also exists: PostgreSQL can store JSON documents directly (as JSON and the faster binary JSONB format), and JSON support was added to the SQL standard itself in SQL:2016.
Scaling: vertical vs horizontal
Relational databases have traditionally scaled vertically — more CPU, memory, and disk in one server. That works, but has limits, and distributing one relational database across many machines is hard. NoSQL systems were designed for horizontal scaling from the start: MongoDB scales out by sharding, distributing data across many servers, and Cassandra is built on clusters of commodity machines.
One relational database that scales differently is SQLite — not a server at all, but an embedded library. It is the most widely deployed database engine in the world, used inside web browsers, operating systems, and mobile phones.
SQL vs NoSQL comparison
| Property | SQL databases | NoSQL databases |
|---|---|---|
| Data model | Tables, rows, columns | Documents, key–value pairs, wide columns, graphs |
| Schema | Fixed, defined before inserting | Flexible, typically no fixed schema |
| Transactions | ACID | ACID in some systems; many use eventual consistency |
| Scaling | Mostly vertical (bigger server) | Horizontal by design (clusters of machines) |
| Querying | Standard SQL, joins across related tables | Database-specific APIs; some SQL-like query languages |
| Best fit | Structured, related data; reporting; financial records | Flexible or unstructured data; very large volumes; real-time web apps |
| Examples | PostgreSQL, MySQL, SQLite, Oracle | MongoDB, Redis, Cassandra, DynamoDB, Neo4j |
How to choose
Start relational for most applications. If your data is structured, related, and must be exact — user accounts, orders, financial records, anything you need to report over — PostgreSQL or MySQL (both open source) or SQLite for embedded use gives you 40 years of standardized querying and ACID guarantees.
Reach for NoSQL when the relational model fights you: data that changes shape constantly, documents that map naturally to JSON, very large volumes on clusters of commodity hardware, or simple lookups at huge scale (a Redis cache in front of a relational database is a classic pattern).
The two families are a spectrum, not a war. MongoDB now has ACID transactions; PostgreSQL now has JSON columns. Pragmatic systems use both in one architecture — polyglot persistence, "not only SQL" — picking per problem. Whatever you choose, benchmark against your own workload: "faster" depends entirely on the queries you actually run.
FAQ
Is NoSQL faster than SQL?
Not in general. Many NoSQL systems prioritize speed and availability for simple lookups at very large scale, which can make them dramatically faster for those patterns. Conversely, relational databases are typically better at complex queries that join related tables. There is no universal answer — measure your own workload.
Can you use SQL with NoSQL databases?
The name itself means "not only SQL": some NoSQL databases offer SQL-like query languages, and many systems combine the two in one architecture. You might store canonical data in a relational database and use a key–value store as a cache in front of it.
Which should I choose for a small web app?
A relational database is usually the right default: PostgreSQL, MySQL, or SQLite depending on your deployment. Choose a document store like MongoDB if your data is naturally JSON-shaped and its structure changes often.
Is MongoDB a NoSQL database?
Yes. MongoDB is a document-oriented NoSQL database, first released in February 2009 by 10gen (now MongoDB Inc.). It stores data in JSON-like BSON documents and supports multi-document ACID transactions since version 4.0 (June 2018).
Sources
- Wikipedia — SQL (en.wikipedia.org/wiki/SQL)
- Wikipedia — NoSQL (en.wikipedia.org/wiki/NoSQL)
- Wikipedia — CAP theorem (en.wikipedia.org/wiki/CAP_theorem)
- Wikipedia — Eventual consistency (en.wikipedia.org/wiki/Eventual_consistency)
- Wikipedia — PostgreSQL (en.wikipedia.org/wiki/PostgreSQL)
- Wikipedia — MongoDB (en.wikipedia.org/wiki/MongoDB)
- Wikipedia — SQLite (en.wikipedia.org/wiki/SQLite)
- Wikipedia — MySQL (en.wikipedia.org/wiki/MySQL)
- Wikipedia — Object–relational impedance mismatch (en.wikipedia.org/wiki/Object–relational_impedance_mismatch)
Share this guide
Related guides
- What is an API? A plain-language guide to how APIs work
What an API is, how REST APIs work over HTTP, the methods you'll actually meet — GET, POST, PUT, PATCH, DELETE — and how to read a response.
- Docker explained: how containers work
Docker explained: what containers are, how Docker Engine uses Linux namespaces and cgroups, how images, Dockerfiles, and Docker Compose fit together, and how Docker compares with virtual machines.
- Git explained: how version control works
Git explained: what version control is, how Git stores history as content-addressed snapshots, why branches are cheap, and how Git and GitHub fit together.