Every new project hits the same question early: do we put the data in a relational database like PostgreSQL or MySQL, or in a NoSQL store like MongoDB, Redis, Cassandra or DynamoDB? The debate is often framed as old versus new, or slow versus scalable. Neither framing is accurate. The two families make different trade-offs, and the right choice depends on the shape of your data and the questions you will ask of it.

This article explains what each side actually is, how the differences show up in real code, and a simple way to decide.

What "SQL" means here

A SQL database is a relational database. Data lives in tables with a fixed set of typed columns. Rows in different tables are connected by keys, and you ask questions with SQL, a declarative language: you describe the result you want and the database figures out how to compute it.

Three properties define the relational model in practice:

  • A schema up front. You declare tables, columns, types and constraints (NOT NULL, UNIQUE, foreign keys) before inserting data. The database rejects rows that break the rules.
  • Joins. Data is normalized: each fact is stored once, and you combine tables at query time.
  • Transactions. Several changes can be grouped so they all succeed or all fail, with strong guarantees (ACID).

PostgreSQL, MySQL, MariaDB, SQLite, SQL Server and Oracle all belong to this family.

What "NoSQL" means here

NoSQL is not one thing. It is an umbrella for databases that do not use the relational table model. The main groups are:

  • Document stores (MongoDB, Couchbase, Firestore): store JSON-like documents. A document can contain nested objects and arrays.
  • Key-value stores (Redis, etcd, DynamoDB in its simplest use): store a value under a key. Very fast lookups by key, little else.
  • Wide-column stores (Cassandra, ScyllaDB, HBase): rows grouped by a partition key, designed to spread large write volumes across many machines.
  • Graph databases (Neo4j): nodes and edges, built for queries that follow relationships many hops deep.

What they share is a willingness to give up some relational features (joins, a strict schema, and in some systems multi-row transactions) in exchange for a data model that fits a particular access pattern, or for easier horizontal scaling.

The same data, two ways

Take a blog: users write posts, and posts have comments.

In SQL you would create three tables and connect them with foreign keys:

CREATE TABLE users (id BIGINT PRIMARY KEY, name TEXT NOT NULL); CREATE TABLE posts (id BIGINT PRIMARY KEY, user_id BIGINT REFERENCES users(id), title TEXT); CREATE TABLE comments (id BIGINT PRIMARY KEY, post_id BIGINT REFERENCES posts(id), body TEXT); SELECT p.title, c.body FROM posts p JOIN comments c ON c.post_id = p.id WHERE p.id = 42; 

In a document store you would often keep a post together with its comments:

{ "_id": 42, "title": "Why indexes matter", "author": { "id": 7, "name": "Amina" }, "comments": [ { "body": "Great post" }, { "body": "What about LSM trees?" } ] } 

Reading the post page is now a single lookup, with no join. That is the main appeal of the document model: data that is read together is stored together.

The cost shows up elsewhere. The author's name is copied into every post. If Amina changes her name, you must update every document that embeds it, or accept stale copies. And a question like "all comments written this week across all posts" is easy in SQL but awkward when comments are buried inside post documents.

The real differences

Schema. Relational databases enforce the schema on write. Document stores are usually "schema on read": the database accepts any shape, and your application code must cope with old and new shapes. That gives speed early in a project and pain later if nobody controls the shape. Many teams add schema validation (MongoDB supports JSON Schema validation) to win some of that safety back.

Queries. SQL is very expressive: joins, grouping, window functions, subqueries. Ad-hoc questions from product or analytics teams are easy to answer. NoSQL stores are usually designed around known access patterns. In DynamoDB or Cassandra, you design tables for the queries you will run; a new kind of query can mean a new table or a new index.

Consistency and transactions. Relational databases give ACID transactions across any rows and tables. Several NoSQL systems now support multi-document transactions too (MongoDB does, DynamoDB has transactional APIs), but they are often more limited or more costly, and some systems default to eventual consistency, where a read right after a write may return the old value.

Scaling. A single relational server scales vertically a long way, and read replicas absorb read-heavy loads. Sharding a relational database across many machines is possible but takes real work. Systems like Cassandra and DynamoDB were built to partition data across nodes from day one, so very large write volumes are their natural territory. That matters at a scale many applications never reach.

Common mistakes

  • Choosing NoSQL "to scale" before there is any load. A well-indexed PostgreSQL instance handles a lot of traffic. Premature distribution adds operational cost and removes features you may need later.
  • Using a document store for highly relational data. If your app is full of many-to-many relationships (orders, products, customers, invoices), you will end up writing joins in application code.
  • Using SQL tables as a cache or a job queue under heavy load. Redis or a dedicated queue usually fits that job better.
  • Ignoring the hybrid option. PostgreSQL has JSONB columns that can be indexed, so you can keep semi-structured fields inside a relational design. Many systems also use both: PostgreSQL as the source of truth, Redis for caching and sessions.

How to decide

Ask these questions in order:

  1. Is the data relational? Many entities with links between them, and correctness matters (money, inventory, bookings)? Start with SQL.
  2. Do you know all your queries in advance? If not, SQL's ad-hoc querying is valuable. If yes, and they are simple key lookups, a key-value or wide-column store may fit.
  3. Is the data naturally a self-contained document? Product catalogs with varied attributes, content blocks, user settings: a document store or a JSONB column works well.
  4. Do you truly need to spread writes across many machines? Very high write throughput across nodes or regions is where Cassandra-style systems are strongest.
  5. What does your team already run well? Operational experience counts for a lot when something breaks at night.

For most web and business applications, a relational database is the safe default, with a NoSQL store added for a specific job such as caching, search or event data.

In short

  • SQL databases: fixed schema, joins, strong transactions, flexible queries.
  • NoSQL databases: several models (document, key-value, wide-column, graph), each tuned for a particular access pattern, often with easier horizontal scaling.
  • The choice is about the shape of your data and your queries, not about which one is newer.
  • Default to SQL for relational, correctness-critical data, and reach for NoSQL when a specific access pattern or scale requirement calls for it.

Originally published at abdeldjalilchougui.biz.