What are the differences between SQL and NoSQL databases?
SQL (relational) databases organize data into tables with a predefined schema, use SQL for queries, and enforce ACID properties (Atomicity, Consistency, Isolation, Durability). They are optimized for complex joins, multi-table transactions, and enforcing referential integrity. Examples: PostgreSQL, MySQL, SQL Server, Oracle.
NoSQL databases is an umbrella term for non-relational stores that trade strict consistency and rigid schemas for flexibility, horizontal scalability, or specialized data access patterns. There are four main categories. Document stores (MongoDB, Firestore) store JSON-like documents and suit hierarchical, varied data. Key-value stores (Redis, DynamoDB) offer O(1) lookups by key; ideal for caching and sessions. Wide-column stores (Cassandra, HBase) organize data into sparse column families, optimized for time-series and write-heavy workloads at massive scale. Graph databases (Neo4j) model data as nodes and edges, making multi-hop relationship traversal efficient.
The core trade-offs map to the CAP theorem: under a network partition, a system can maintain either Consistency or Availability, but not both. Most SQL databases prioritize consistency; many NoSQL stores (like Cassandra and DynamoDB) prioritize availability and offer eventual consistency. This is not a defect -- it is an explicit engineering choice for systems where uptime and scale matter more than strict consistency.
Scaling patterns differ fundamentally. SQL databases scale vertically or with read replicas; sharding relational databases is complex and often breaks joins. NoSQL stores like Cassandra are designed for horizontal sharding from the start -- you add nodes to increase capacity linearly.
Choose SQL when: you need ACID transactions across multiple entities, your data is structured and relational, and you need ad-hoc query flexibility. Choose NoSQL when: you need horizontal scale beyond a single machine, your access patterns are well-defined and simple, your data is inherently document-shaped or graph-shaped, or you need specific performance characteristics such as sub-millisecond cache reads.
| Aspect | SQL (Relational) | NoSQL |
|---|---|---|
| Schema | Predefined, enforced at write | Flexible or schemaless |
| Transactions | Full ACID across tables | Varies -- often document-level or eventual consistency |
| Scaling | Vertical; read replicas; complex sharding | Horizontal sharding built-in |
| Query language | Declarative SQL; ad-hoc joins | Limited; API-driven; no general joins |
| Data model | Tables with rows and columns | Documents, key-value, wide-column, graph |
| Consistency model | Strong consistency (ACID) | Ranges from strong to eventual |
| Best fit | OLTP, financial systems, complex queries | High-scale, simple access patterns, flexible data |
Candidate can describe the key differences (schema, ACID, scaling) and name examples of each, but cannot explain CAP theorem trade-offs, cannot distinguish the four NoSQL categories, or cannot reason about which to choose for a given use case.
Candidate precisely contrasts ACID vs eventual consistency, explains horizontal vs vertical scaling, identifies the four NoSQL families with examples, references CAP theorem accurately, and gives defensible selection criteria for realistic scenarios.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment