SQL vs NoSQL Databases
SQL and NoSQL describe overlapping families of database interfaces and models. Relational, document, key-value, wide-column and graph systems offer different query, consistency and scaling tradeoffs.
Choose a data model from its relationships and access needs rather than a rigid SQL-versus-NoSQL slogan.
A team building a chat app hears that "NoSQL scales better" and moves everything, including billing, into a document store. Six months later they are writing code by hand to keep invoice totals consistent. Neither family is better in general; each is better at particular jobs.
The rule
SQL: declare the shape, ask anything. NoSQL: design for the access, scale out.
SQL databases are relational: fixed tables, keys linking them, and one standard language for any question. You design the shape of the data, and queries adapt to it.
NoSQL is a loose name for databases that are not built around relational tables. There are four big families:
| Family | Stores | Good at | Example |
|---|---|---|---|
| Key-value | a value per key | very fast lookups by key | Redis |
| Document | JSON-like documents | records with varying shape | MongoDB |
| Wide-column | rows with flexible column sets | huge write volumes | Cassandra |
| Graph | nodes and edges | following relationships | Neo4j |
With NoSQL you usually start from the question — "load a user's profile by id" — and shape the data so that one question is cheap. Data is often duplicated on purpose. Many NoSQL systems were built to spread across many machines easily, and some relax consistency to do so, though modern ones increasingly offer transactions too.
"NoSQL" does not mean "no query language" — most have one; it is just not SQL. And the line is blurring: PostgreSQL can store JSON documents, and some NoSQL stores accept SQL-like queries.