SQL vs NoSQL — Choosing a Datastore
A decision framework that goes beyond "relational vs document," the four NoSQL families and what each is genuinely for, and why the honest default is Postgres.
#The framing that scores
"SQL vs NoSQL" is a bad question, because NoSQL isn't one thing — a key-value store and a graph database have nothing in common. The question interviewers actually want answered is:
What are the access patterns, and what's the smallest system that serves them?
Answer that, and the datastore choice usually falls out. Lead with the technology name and you've skipped the reasoning that gets scored.
#Relational databases
Postgres, MySQL, and friends. Data in tables with a fixed schema, related by keys, queried with SQL.
What you actually get, and why it's more than people credit:
- ACID transactions across multiple rows and tables. The killer feature. ACID is four promises about a group of changes: they all happen or none do (atomic), they leave the data obeying its rules (consistent), they don't see each other half-finished (isolated), and once confirmed they survive a crash (durable). Moving money between accounts, or reducing stock while creating an order, needs exactly that — and rebuilding it yourself on a store that doesn't offer it is genuinely hard.
- A query planner. You describe what you want; the database works out how to get it — which index to use, which table to read first. A new kind of question usually needs no redesign, just an index.
- Joins — combining rows from two tables in one query. This is what lets data stay normalised: each fact stored in exactly one place, so an update can't leave two copies disagreeing.
- Constraints as guarantees — foreign keys, uniqueness, checks. Correctness enforced by the database rather than hoped for in every application that touches it.
- Decades of operational tooling, and engineers who already know it.
Real limits:
- Writes scale to one machine. You can add read replicas freely, but the primary is the write ceiling — call it ~10–50K writes/s for tuned commodity hardware.
- Horizontal sharding is manual and painful. Once sharded, cross-shard joins and transactions largely go away, and you've kept the costs of SQL while losing its main benefits.
- Rigid schema — migrations on huge tables need care (though
ADD COLUMNwith a default is cheap in modern Postgres).
Note also that "SQL doesn't scale" is increasingly outdated: NewSQL systems (Spanner, CockroachDB, TiDB, Vitess, Aurora) offer horizontal scale with SQL and transactions, paying for it in latency (cross-node coordination) and cost. Naming this category is worth doing — it defeats the false dichotomy the question implies.
#The four NoSQL families
#Key-value stores
Redis, DynamoDB, Memcached, Riak
A dictionary spread across many machines. get(key), put(key, value). The value is opaque — the store treats it as a blob of bytes and can't look inside it, so you can't ask "find me all values where status is active".
Strengths: the simplest possible data model, which means it splits across machines perfectly — double the nodes, double the throughput. Single-digit-millisecond latency at essentially any scale.
Limits: you can only fetch by key. No querying by value, no joins, no range scans (unless the store adds sort keys, as DynamoDB does).
Use for: sessions, caching, feature flags, rate-limit counters, user preferences, shopping carts.
#Document stores
MongoDB, DynamoDB, Couchbase, Firestore
Self-describing documents (JSON-ish) in collections. Queryable inside the document, and nested structures are stored together.
Strengths: flexible schema (genuinely useful when different records have different fields — product catalogs, user-generated content). Fetching one whole object — say, an order with its line items and shipping address — is one read with no joins, because the related data is embedded inside the same document.
Limits: denormalization means duplicated data, so updates touch many documents. Transactions that span several documents exist in modern versions, but the store is not built around them: they are slower and more limited than in a relational database. Joins are weak.
Use for: content management, catalogs, event/activity records, user profiles with varying fields.
The modeling rule: embed what you read together, reference what you update independently. An order's line items are always shown with the order, so embed them. The customer who placed it changes their address on their own schedule, so store the customer separately and keep just their ID in the order. Getting this wrong is the usual failure, in one of two directions. Embed an array that grows without limit (every comment ever posted on a popular item) and the document hits MongoDB's 16 MB size cap. Or split everything into separate documents linked by ID, and you've rebuilt a relational schema without the joins that make one work.
#Wide-column stores
Cassandra, ScyllaDB, HBase, Bigtable
Every row is addressed by two things: a partition key, which decides which machine holds it, and a clustering key, which decides what order rows sit in on that machine. So "all messages in chat 42, newest first" is one partition read in sorted order — which is exactly why these stores are so fast at that shape of question.
Strengths: exceptional write throughput (LSM-based, so writes are sequential appends), linear scale, no single point of failure (peer-to-peer, no leader), tunable consistency (each query chooses how many replicas must respond — one for speed, a majority for stronger guarantees), and outstanding performance for time-ordered range scans within a partition.
Limits: you must know your queries before you design the tables. Nothing works out a query plan for you, and joins don't exist. A question you didn't design for means a new table, filled by a new write path. Deleting doesn't remove data either — it writes a tombstone, a marker saying "this is gone", which is itself data you now have to read past until it's cleaned up.
Use for: time series, event logs, message history, IoT telemetry, feeds — anything write-heavy, append-mostly, and queried by a known key with a time range.
#Graph databases
Neo4j, Neptune, JanusGraph
Nodes and edges as first-class citizens, with relationship traversal as the primitive.
Strengths: multi-hop traversals ("friends of friends who like X"). In SQL each hop is another join of the friendships table with itself, and the intermediate results multiply with every hop. A graph database stores each node's connections directly alongside it, so it just follows pointers outward from the starting node. The cost grows with how much of the graph you actually walk, not with the size of the whole dataset.
Limits: hard to shard (relationships cross partitions by nature), narrower operational ecosystem, and often unnecessary — one or two hops is fine in a relational database with the right indexes.
Use for: social graphs, fraud rings, recommendation networks, permission hierarchies, knowledge graphs. Note that most large social networks do not use a graph database for the primary store; they use sharded MySQL or similar, with a service on top that exposes graph-style operations like "get this user's friends" (Facebook's TAO is the famous example). Knowing that is a nice piece of nuance.
#The decision framework
Walk these in order:
1. Do you need multi-record ACID transactions? If invariants span records — money, inventory, bookings — start relational. Everything else is a workaround.
2. What's the write throughput? Under ~10K/s sustained: single relational primary. Above ~50K/s: partitioned store, likely wide-column, or a sharded/NewSQL relational system.
3. What's the data volume? Under a few TB: one machine (with replicas). Hundreds of TB: distributed by necessity. Petabytes of blobs: object storage with metadata in a database.
4. Are the access patterns known and stable? Known and fixed → wide-column/KV is safe and fast. Evolving or ad-hoc → you want a query planner, i.e. SQL.
5. What's the read:write ratio? Very read-heavy → replicas plus caching, which favors relational. Write-heavy and append-only → LSM-based stores.
6. What consistency does each operation need? Per the spectrum — and note it varies by operation, so polyglot persistence is normal and worth proposing.
#Polyglot persistence
Real systems use several stores, each for what it's good at. Proposing this — with justification, not as a shopping list — is a strong signal:
| Data | Store | Why |
|---|---|---|
| Users, orders, payments | Postgres | Transactions, constraints, ad-hoc queries |
| Sessions, rate limits | Redis | Sub-ms, TTL native, disposable |
| Message / event history | Cassandra | Write-heavy, time-ordered, huge volume |
| Photos, video | S3 + CDN | Cheap bytes; DBs are a terrible fit for blobs |
| Full-text search | Elasticsearch | Inverted index (word → documents containing it), relevance ranking |
| Feed / analytics rollups | ClickHouse / Druid | Columnar storage: sums over one column read only that column |
| Recommendations | Precomputed → Redis | Latency; compute offline |
The cost to acknowledge: every additional store is operational surface, another failure mode, another consistency boundary, and another thing on-call must understand. "I'd use three datastores here, and here's why each earns its place" is strong; naming seven without justification is the buzzword failure mode.
#Common traps
- Choosing by scale you don't have. Cassandra at 200 QPS is a mistake that costs you joins, transactions, and ad-hoc queries in exchange for nothing.
- "NoSQL is schemaless, so no modeling needed." Backwards. The schema moves from the database into your application, where it's enforced by nothing and understood by no one. NoSQL demands more upfront modeling. In Postgres, a query you didn't plan for usually just needs a new index. In a key-value or wide-column store, it can mean a new table and rewriting how data is written.
- Ignoring the join you'll need later. Denormalization is a bet that the access pattern won't change. Sometimes right; make it knowingly.
- Forgetting operational cost. Managing a Cassandra ring is a specialist skill. If the team is three engineers, that's a real argument against it — and mentioning team/operational fit is a mature thing to say in a design interview.
#Check yourself
What question should replace "SQL or NoSQL?"Show answer
What is the relational database's real ceiling, and what are its biggest strengths?Show answer
What does a key-value store give up for its near-perfect scaling?Show answer
Document stores: what's the modelling rule?Show answer
Wide-column stores: what do the partition key and clustering key do, and what's the catch?Show answer
When does a graph database earn its place?Show answer
Walk the decision framework for picking a datastore.Show answer
What does polyglot persistence cost?Show answer
#What to carry forward
- Start from access patterns; "SQL versus NoSQL" is the wrong question.
- The honest default is Postgres, with a stated threshold for when to revisit.
- Each NoSQL family is for a specific shape: key-value lookups, documents read whole, wide-column time ranges, graph traversals.
- NoSQL needs more up-front modelling, not less — the schema moves into your code.
- Mixing stores is normal, but each one must earn its operational cost; NewSQL breaks the false dichotomy.