SQL databases provide ACID guarantees and relational data modeling. NoSQL databases trade some consistency guarantees for horizontal scalability and flexible schemas. Knowing when to use each is fundamental to system design.
SQL databases organize data into tables with rows and columns, with strict schemas and relationships enforced through foreign keys.
ACID Properties:
Examples: PostgreSQL, MySQL, SQLite, Oracle, SQL Server
Strengths:
Weaknesses:
Store data as JSON/BSON documents. Flexible schema — each document can have different fields.
Examples: MongoDB, Firestore, CouchDB
Best for: Content management, user profiles, product catalogs, any data that varies in shape
// User document — fields vary per user
{
"_id": "user123",
"name": "Alice",
"preferences": { "theme": "dark" },
"social": { "twitter": "@alice" }
}
Simple key→value pairs. Extremely fast.
Examples: Redis, DynamoDB (also document), Memcached
Best for: Sessions, caching, real-time leaderboards, feature flags
Data organized by column families rather than rows. Optimized for time-series and analytical workloads.
Examples: Cassandra, HBase, Bigtable
Best for: Time-series data, IoT sensor data, activity feeds, write-heavy workloads at massive scale
Nodes and edges model relationships directly.
Examples: Neo4j, Amazon Neptune
Best for: Social networks, recommendation engines, fraud detection — any problem where relationships are first-class
| Need | Choose | |---|---| | Complex queries, JOINs, reporting | SQL | | Financial transactions, strong consistency | SQL | | Flexible/evolving schema | Document (MongoDB) | | Extreme write throughput | Column-family (Cassandra) | | Key-value lookups, caching | Redis, DynamoDB | | Graph traversals | Neo4j | | Time-series data | InfluxDB, TimescaleDB, Cassandra | | Multi-region active-active | Cassandra, DynamoDB |
Real systems often use both: