What is NoSQL? NoSQL vs SQL databases explained simply

NoSQL is a family of databases that don't store data in fixed tables. Here are the four main kinds, what they're good at, what you give up, and a simple way to choose between SQL and NoSQL.

Two kinds of storage side by side. On the left, a neat filing cabinet with labelled drawers in strict rows, labelled SQL: same columns for every row. On the right, a shelf of different containers: a box of key tags, a folder of documents, a tall column of drawers and a pinboard of photos joined with string, labelled NoSQL: shape fits the data.
Fig. 1 — SQL is one well-organised filing cabinet. NoSQL is a set of different containers, each shaped for one kind of job.

For decades, if you said “database”, people pictured tables: rows and columns, like a spreadsheet, queried with a language called SQL. Banks, shops and schools all ran on them, and most still do.

Then, in the 2000s, companies like Google and Amazon hit problems that tables handled awkwardly: billions of users, data that didn’t fit neat columns, and the need to spread data across thousands of machines. They built new kinds of databases, and the industry gave the whole group a catchy name: NoSQL.

This guide explains what NoSQL means, the main kinds, and how to choose between SQL and NoSQL in a system design.

What is NoSQL?

NoSQL is a broad name for databases that don’t use the classic table-and-row model of relational (SQL) databases. Today it’s usually read as “Not only SQL”, because many NoSQL databases have their own query languages, and some even support SQL-like queries.

What they share is a general direction:

  • Flexible structure. You don’t have to declare every column up front. Two records can have different fields.
  • Built to spread out. Most are designed to run across many servers and grow by adding machines (scaling out). See horizontal scaling.
  • Shaped for specific access patterns. Each kind is very good at certain questions and weaker at others.

The four main kinds of NoSQL database

Four cards. Key-value: a key user:42 points to a blob of data; examples Redis, DynamoDB; good for caching and sessions. Document: a JSON document for an order with nested items; example MongoDB; good for catalogues and user profiles. Wide-column: a row key with many columns spread across time; a chat ID row holding millions of timestamped messages; examples Cassandra, HBase, Bigtable; good for huge write-heavy data like events and messages. Graph: circles for people named Asha, Ravi, Meena and Ali joined by lines labelled follows; example Neo4j; good for social networks and recommendations.
Four NoSQL families, each built around a different shape of data.

1. Key-value stores. The simplest: save a value under a key, get it back by that key. Very fast and easy to scale. Examples: Redis, Amazon DynamoDB. See what a key-value store is.

2. Document databases. Store each record as a document, usually JSON-like, which can hold nested lists and objects. An order document can contain its items right inside it. Examples: MongoDB, Couchbase, Firestore.

3. Wide-column stores. Rows are found by a key, but each row can have a huge, changing set of columns, and data is spread across many machines by design. Built for very large amounts of writes. Examples: Apache Cassandra, HBase, Google Bigtable.

4. Graph databases. Store things (nodes) and the relationships between them (edges) as first-class data. Questions like “friends of my friends who like cricket” are natural. Examples: Neo4j, Amazon Neptune.

Our deep dive on types of databases covers each one with examples and puzzles.

SQL vs NoSQL: the real differences

SQL (relational) NoSQL
Data shape Tables with fixed columns Key-value, documents, wide rows or graphs
Changing structure Planned changes to the table schema Flexible; new fields can just appear
Relationships Joins across tables are easy Usually avoided; related data is stored together
Transactions Strong, multi-row transactions are the norm Varies; often limited to one record or key
Scaling Usually scale up first; scaling out is harder Usually designed to scale out
Queries Very flexible: ask almost any question Fast for the questions you designed for
Examples PostgreSQL, MySQL, Oracle, SQL Server Redis, MongoDB, Cassandra, Neo4j

The big trade-off in one line: SQL is flexible about questions; NoSQL is flexible about data shape and scale. With SQL, you can ask new questions later with a new query. With most NoSQL databases, you design your data around the questions you know you’ll ask.

When to choose NoSQL

NoSQL tends to fit when:

  • The data doesn’t have a fixed shape. Product catalogues where a phone and a sofa have totally different attributes suit documents.
  • You need huge scale for simple lookups. Billions of sessions, carts or events looked up by ID suit key-value and wide-column stores.
  • Writes are massive and constant. Sensor readings, chat messages, activity logs.
  • Relationships are the data. Social graphs and fraud rings suit graph databases.

When to stay with SQL

SQL tends to fit when:

  • Correctness across many records matters. Moving money between two accounts must update both or neither. Relational transactions do this well.
  • You’ll need many different questions over time. Reports, admin screens and analytics love SQL.
  • Your data is naturally related. Customers, orders, products and payments that link to each other.
  • You’re not at huge scale yet. A well-tuned relational database on a good machine, with replicas and a cache, handles far more than most products ever need.

A common, sensible default in interviews and real life: start with a relational database, and add NoSQL where a specific need shows up. Many large systems use both, each for what it’s best at. That’s called polyglot persistence.

Common misconceptions

“NoSQL means no structure.” The database may not enforce a schema, but your application still expects certain fields. The structure moves from the database into your code.

“NoSQL is faster than SQL.” For the lookups it was designed for, often yes. For flexible queries and joins, a relational database is usually faster and simpler.

“NoSQL can’t be consistent.” Many NoSQL databases let you choose stronger or weaker consistency per request. See eventual consistency.

“SQL databases can’t scale.” They scale very far with bigger machines, read replicas, caching and, when truly needed, sharding.

Key takeaways

  • NoSQL means databases that don’t use the classic table model; read it as “not only SQL”.
  • Four main kinds: key-value, document, wide-column, graph.
  • SQL is flexible about questions; NoSQL is flexible about data shape and scale.
  • Choose NoSQL for flexible data, huge simple lookups, constant writes or relationship-heavy data.
  • A safe default: start relational, add NoSQL for specific needs.

Frequently asked questions

What is NoSQL in simple words?

NoSQL is a group of databases that store data in ways other than rows and columns, such as key-value pairs, JSON documents, wide rows or graphs. They’re often built to handle large scale and flexible data.

What does NoSQL stand for?

It’s commonly read as “Not only SQL”. It signals databases that go beyond the traditional relational, table-based model, not necessarily databases that reject SQL entirely.

Is MongoDB SQL or NoSQL?

MongoDB is a NoSQL document database. It stores data as JSON-like documents instead of rows in tables.

Which is better, SQL or NoSQL?

Neither is better overall. SQL suits related data, transactions and flexible queries. NoSQL suits flexible data shapes and very large scale with predictable lookups. Many systems use both.

What are examples of NoSQL databases?

Redis and DynamoDB (key-value), MongoDB and Couchbase (document), Cassandra and HBase (wide-column), and Neo4j (graph).

Comments

LEAVE A COMMENT
No sign-up. Comments appear after a quick review.