How do you choose between a SQL and a NoSQL database?
EasyConceptDatabases: Replication & Sharding
Answer
Choose a relational (SQL) database when data is structured and related and you need joins, ACID transactions and strong consistency. Choose a NoSQL database when you need flexible schemas, very high write throughput, or easy horizontal scaling for simple access patterns.
- SQL (PostgreSQL, MySQL): orders, payments, inventory and user accounts.
- Key-value (Redis, DynamoDB): sessions, caches and lookups by ID.
- Wide-column (Cassandra, HBase): high-volume, time-ordered writes such as messages, events and metrics.
- Document (MongoDB): nested records with varying fields, such as product catalogues. Graph (Neo4j): relationship-heavy queries.
- The boundary is blurring: many SQL databases can be sharded, and many NoSQL stores offer transactions. Choose by access pattern, not by trend.
More in Databases: Replication & Sharding
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | How do you choose between a SQL and a NoSQL database? | Concept | Easy | Read the answer to How do you choose between a SQL and a NoSQL database? | |||
| 2 | What is database replication, and how do synchronous and asynchronous replication differ? | Concept | Medium | Read the answer to What is database replication, and how do synchronous and asynchronous replication differ? | |||
| 3 | What is sharding, and how do you choose a shard key? | Concept | Medium | Read the answer to What is sharding, and how do you choose a shard key? | |||
| 4 | What problems does sharding introduce, and how are they handled? | Concept | Hard | Read the answer to What problems does sharding introduce, and how are they handled? |