SQL vs NoSQL: Choosing the Right Database (Not the Trendiest One)
When relational databases win, when NoSQL wins, and why 'just use Postgres' is good advice more often than you'd think — plus where it falls short.
Every few years, someone declares that SQL is dead. Then reality reasserts itself. SQL databases handle the majority of production workloads worldwide, and they'll continue to do so. But NoSQL databases exist for good reasons — specific problems where relational models create more friction than they solve.
The trick is knowing which problems those are.
What SQL Databases Actually Give You
Relational databases (PostgreSQL, MySQL, SQL Server, SQLite) store data in tables with defined schemas. Rows have columns. Columns have types. Tables relate to each other through foreign keys. This sounds simple because it is — and that simplicity has carried the industry for 50 years.
The real value isn't the table structure, though. It's the guarantees:
ACID transactions. Your multi-step operations either complete entirely or not at all. Transfer money between accounts? Both the debit and credit happen, or neither does. This isn't a feature you appreciate until you've debugged a system that doesn't have it. Complex queries. JOINs across multiple tables, aggregations, window functions, subqueries, CTEs. SQL is a declarative query language — you describe what you want, and the query planner figures out how to get it efficiently. When your data has relationships (and it usually does), SQL handles them naturally. Schema enforcement. The database rejects data that doesn't match the schema. This catches bugs at the boundary rather than letting corrupt data propagate through your system. Constraints, foreign keys, unique indexes — these are all a form of runtime validation that your application code doesn't have to handle. Mature tooling. Decades of optimization, monitoring tools, backup strategies, replication patterns. PostgreSQL's query planner is one of the most sophisticated pieces of software ever written. You benefit from that without thinking about it.What NoSQL Databases Give You
"NoSQL" covers several completely different database types. Lumping them together is like comparing cars, boats, and planes because they're all "not trains."
Document databases (MongoDB, CouchDB, Firestore) store JSON-like documents. No fixed schema — each document can have different fields. Good when your data is naturally hierarchical, when the schema changes frequently during early development, or when you're storing varied content like CMS entries or user profiles with optional fields. Key-value stores (Redis, DynamoDB, Memcached) map keys to values with extremely fast lookups. Redis is often used as a cache layer, session store, or message broker. DynamoDB handles massive throughput with predictable latency. The trade-off: you can only query by key (or by indexes you define up front in DynamoDB's case). Graph databases (Neo4j, Amazon Neptune) model data as nodes and edges. When your core queries are "find all friends-of-friends" or "what's the shortest path between X and Y," graph databases are dramatically faster than relational JOINs across self-referencing tables. Wide-column stores (Cassandra, ScyllaDB, HBase) handle massive write throughput across distributed clusters. Time-series data, event logs, IoT sensor data — workloads where you're writing millions of rows per second and reading in sequential ranges.When SQL Wins
Most of the time. Seriously.
If your application has users, orders, products, transactions, accounts, permissions, or any domain where entities relate to each other — SQL is the natural fit. The relational model was designed for exactly this, and decades of optimization mean it handles these workloads extremely well.
Specific SQL wins:
- Complex reporting and analytics (aggregations, window functions, GROUP BY across dimensions)
- Data integrity is critical (financial systems, healthcare, anything regulated)
- The schema is known and relatively stable
- You need ad-hoc queries (explore data without pre-defining access patterns)
- You want one database that handles reads, writes, transactions, and search reasonably well
When NoSQL Wins
NoSQL databases win when the relational model creates friction rather than reducing it.
- Caching layer: Redis is the right tool. Don't store cache in PostgreSQL.
- Session storage: Key-value stores handle this cleanly.
- Real-time leaderboards, counters, rate limiting: Redis sorted sets, atomic increments.
- Massive write throughput with simple access patterns: Cassandra or DynamoDB. When you're ingesting millions of events per second, a distributed key-value store handles the write pressure better than a relational database.
- Highly variable schema: If every document has a genuinely different shape and you'd need hundreds of nullable columns in SQL, a document store makes more sense.
- Graph traversal: Social networks, recommendation engines, fraud detection. If you're doing recursive JOINs in SQL, you probably want a graph database.
"Just Use Postgres" — When It's Right
There's popular advice that goes: "just use Postgres for everything." It's surprisingly good advice for a surprisingly large number of applications.
PostgreSQL supports JSON columns (with indexing), full-text search, geospatial queries (PostGIS), pub/sub (LISTEN/NOTIFY), and even time-series with extensions (TimescaleDB). A single PostgreSQL instance can handle thousands of transactions per second. Most applications will never outgrow it.
The "just use Postgres" advice is right when:
- You're building a startup or small-to-medium application
- You don't want to operate multiple database systems
- Your data has relationships
- You need transactions
- Your scale is under a few million rows per table (which covers most apps)
The advice is wrong when:
- You need sub-millisecond caching (use Redis alongside Postgres)
- You're writing millions of events per second (consider a dedicated time-series or event store)
- Your access patterns are purely key-value at massive scale (DynamoDB is purpose-built for this)
- Graph traversal is your core query pattern
The key insight: many successful applications use Postgres as the primary database AND a specialized database for specific needs. Postgres for your domain data, Redis for caching and sessions, maybe Elasticsearch for full-text search on large corpuses. These aren't competing choices — they're complementary tools.
Learning the Fundamentals
SQL is a foundational skill regardless of what databases you end up using. Even if you work with MongoDB day-to-day, understanding relational modeling, normalization, and query optimization makes you a better developer. Most NoSQL databases borrow concepts from relational theory anyway.
Start with SQL. Learn SELECT, JOIN, GROUP BY, subqueries, and indexing strategy. Then learn about the specific NoSQL tools as your projects need them. CodeUp has interactive SQL exercises that run real queries against actual databases in your browser — a good way to build practical SQL skills without installing anything locally.