DBMS · Design and models

SQL vs NoSQL databases

Easysqlnosqldesign

Interview question

What is the difference between SQL and NoSQL databases, and when would you choose each?

How to answer

The short answer

SQL (relational) databases store data in tables with a fixed schema, and rows in different tables are linked by keys. They use SQL for queries and offer ACID transactions. Examples are PostgreSQL, MySQL and SQL Server.

NoSQL databases is a broad label for databases that do not use the model. They come in several kinds:

  • Document: stores JSON-like documents, for example MongoDB.
  • Key-value: stores a value under a key, for example Redis.
  • Wide-column: stores rows with flexible columns, for example Cassandra.
  • Graph: stores nodes and relationships, for example Neo4j.
SQLNoSQL
Schemafixed, defined firstflexible, can change per record
Relationshipsjoins between tablesusually stored inside one record
Transactionsstrong ACIDvaries, often weaker across records
Scalingusually scale up one server, with read replicasoften built to spread across many servers

When to choose SQL: the data is structured, the relationships matter, and correctness is important, as in payments, orders and inventory.

When to choose NoSQL: the data shape varies a lot, you need very high write volume or very low latency at large scale, or the data is naturally a document or a graph, such as a product catalogue or a social network.

A common mistake is to say NoSQL is faster. It is not faster in general. It is faster for the access patterns it was designed for. Many systems use both: a relational database for orders, and a key-value store for caching sessions.

Interview shortcut

> Pick SQL when relationships and correctness matter. Pick NoSQL when the shape or the scale does not fit tables.