"NoSQL" is not one kind of database, so comparing "SQL vs NoSQL" as two options hides most of the useful detail. This cheat sheet puts the relational model next to the three NoSQL families you are most likely to meet as a backend developer: document stores, key-value stores and wide-column stores. Graph databases are a fourth family, worth a look when your queries mostly follow relationships many hops deep.
The four options
Relational (SQL). PostgreSQL, MySQL, SQLite, SQL Server. Tables with typed columns, a schema enforced on write, joins between tables, and ACID transactions across any rows. The query language is expressive enough to answer questions nobody planned for.
Document store. MongoDB, Couchbase, Firestore. Each record is a JSON-like document that can nest objects and arrays. Data that is read together is stored together, so a typical page load is a single lookup. The schema is flexible, which helps early and needs discipline later.
Key-value store. Redis, etcd, Memcached, and DynamoDB in its simplest form. You put a value under a key and get it back by that key. Very fast and simple, but you cannot ask "which values match this condition" unless you build that yourself.
Wide-column store. Cassandra, ScyllaDB, HBase. Rows are grouped by a partition key and spread across many nodes. Writes are cheap and scale out by adding machines. You design tables around the queries you will run, often duplicating data across several tables.
Side by side
| Relational | Document | Key-value | Wide-column | |
|---|---|---|---|---|
| Data model | tables, rows | JSON documents | key to value | partitions of rows |
| Schema | enforced on write | flexible | none | defined per table, query-first |
| Querying | full SQL, joins | rich filters, no real joins | by key only | by partition key, limited |
| Transactions | ACID, any rows | multi-document, with limits | per key, some atomic ops | per partition, lightweight |
| Scaling | vertical, replicas, sharding is work | sharding built in | sharding built in | built for many nodes |
| Typical use | business data, money | catalogs, content | cache, sessions | events, time series |
A few cells need nuance. MongoDB supports multi-document ACID transactions, and Redis offers atomic commands, MULTI/EXEC and Lua scripts. Cassandra lets you tune consistency per query, from a single replica to a quorum. And PostgreSQL's JSONB type lets a relational database store and index document-style data.
What each one makes easy and hard
Relational. Easy: ad-hoc questions, reports, keeping data correct with constraints, transactions that span many tables. Hard: very high write volume across many machines, and data whose shape changes constantly.
Document. Easy: loading a whole object in one read, evolving fields without migrations, storing records with varied attributes. Hard: many-to-many relationships, queries that cut across documents, keeping duplicated data in sync.
Key-value. Easy: caching, sessions, rate limiting counters, feature flags, anything accessed by an exact key. Hard: anything else. Many key-value stores (Redis in particular) keep data in memory, so size and persistence settings matter.
Wide-column. Easy: heavy, continuous writes, data spread across regions, queries that always start from a known partition key ("all readings from sensor 17 today"). Hard: ad-hoc queries, joins, and changing access patterns after launch.
Common mistakes
- Picking NoSQL for scale you do not have yet, and losing joins and constraints you need now.
- Modelling relational data as documents, then rebuilding joins in application code.
- Using a key-value cache as the only copy of important data without understanding its persistence settings.
- Designing Cassandra tables like SQL tables. Partition keys and query patterns come first.
When to pick which
-
Pick relational as the default for business applications: users, orders, payments, inventory, anything where correctness and flexible querying matter. Add
JSONBcolumns for the semi-structured parts. - Pick a document store when each record is naturally a self-contained object (product catalog, CMS content, user profiles with varied fields) and most reads fetch one object at a time.
- Pick a key-value store next to your main database for caching, sessions, queues and counters. It is rarely the only database in a system.
- Pick a wide-column store when you have very high write throughput, data that must spread across many nodes or regions, and queries you can define in advance.
- Mix them when needed. A common shape: PostgreSQL as the source of truth, Redis as the cache, and a specialised store only for the workload that truly needs it.
Originally published at abdeldjalilchougui.biz.
Top comments (0)