What is the difference between SQL and NoSQL databases?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for System Design development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
SQL (Relational) databases store data in structured tables with predefined schemas, use SQL for queries, and enforce ACID transactions. Relationships are defined via foreign keys. Examples: MySQL, PostgreSQL, Oracle, SQL Server. Best for: complex queries with joins, strong consistency requirements, well-defined structured data, financial transactions. NoSQL databases store data in flexible, schema-less formats optimized for specific access patterns. Types: Document (MongoDB, Couchbase — JSON documents); Key-Value (Redis, DynamoDB — ultra-fast lookup by key); Column-family (Cassandra, HBase — wide rows, good for time-series); Graph (Neo4j, Amazon Neptune — relationship-heavy data). Best for: rapidly changing schemas, massive scale, specific access patterns, unstructured data, horizontal scaling. Key differences: Schema: SQL is rigid (ALTER TABLE); NoSQL is flexible (add fields anytime). Scaling: SQL scales vertically easily, horizontally is complex; NoSQL designed for horizontal. Consistency: SQL typically ACID; NoSQL often eventual consistency (BASE). Queries: SQL supports complex joins; NoSQL queries limited to access patterns the data model was designed for. Choosing: structured + complex queries + ACID → SQL; flexible schema + massive scale + simple access patterns + horizontal scaling → NoSQL. Many modern architectures use both — SQL for core business data, Redis for caching, Elasticsearch for search, Cassandra for time-series.
Common Mistake
A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.