Skip to main content
06

SQL vs NoSQL: how do you choose?

EasyDatabasesSQLNoSQL

How do you choose between a SQL (relational) and a NoSQL database?

TL;DR

Choose by data shape and access patterns, not fashion. Relational databases (PostgreSQL, MySQL) fit structured, related data with joins, ad-hoc queries, constraints and ACID transactions; they're the right default for most applications. NoSQL covers several families, each strong at one thing: document stores (MongoDB) for flexible nested records read as a whole, key-value (Redis, DynamoDB) for very fast lookups by key, wide-column (Cassandra) for huge write-heavy workloads, and graph (Neo4j) for relationship traversal.

Key points

  • SQL: a fixed schema, normalized data, powerful queries, and strong consistency. Scaling writes beyond one machine takes work (sharding), though read replicas are easy.
  • NoSQL: usually designed around known queries up front, scales horizontally by partition key, and often trades joins and strict consistency for scale and availability.
  • The lines have blurred: PostgreSQL has JSONB and full-text search; MongoDB has multi-document transactions.
  • Polyglot persistence is normal: PostgreSQL as the source of truth, Redis for cache, Elasticsearch for search.

Example

  • Bank accounts and orders: PostgreSQL (transactions, constraints).
  • Product catalog with very different attributes per category: PostgreSQL with JSONB, or MongoDB.
  • Session store or leaderboard: Redis.
  • IoT telemetry at millions of writes per second: Cassandra or a time-series database.
  • Single-table app with known access patterns at massive scale: DynamoDB.

Common follow-ups

  • Is NoSQL "schemaless"? The database doesn't enforce a schema, but your code still assumes one. Schema-on-read moves validation into the application.
  • Can SQL scale? Yes: read replicas, partitioning, and distributed SQL (CockroachDB, Spanner, Aurora) for scaling writes.

What interviewers look for

Tip

Start from the access patterns and consistency needs, name the NoSQL family that fits, and default to relational when unsure.

  • Red flag: "NoSQL because it's faster and scales", with no word about queries or consistency.

Was this helpful?

Related questions