Question #1 of 60•Databases•Medium• ~3 min read

How do you choose between SQL and NoSQL databases for a system?

Executive Takeaway

Evaluate structural requirements, scalability patterns, and data consistency models to decide between relational and non-relational storage engines.

Architectural Breakdown & AnalysisFAANG Aligned

The choice between SQL (Relational) and NoSQL (Non-Relational) databases is not about which is "better," but rather which matches your system's data structure, query patterns, and scale constraints.

1. SQL Databases (e.g., PostgreSQL, MySQL)

  • Data Structure: Strict tabular schema with defined relationships (Foreign Keys). Ideal for normalized data.
  • Consistency: Strict ACID compliance by default. Best for financial ledgers and transactions where inconsistency causes immediate failure.
  • Scaling: Primarily vertical (scaling CPU/RAM). Horizontal scaling requires master-replica reads or complex application-layer sharding.
  • Queries: Powerful SQL engine supporting multi-table JOINs and complex analytical aggregations.

2. NoSQL Databases (e.g., MongoDB, DynamoDB, Cassandra)

  • Data Structure: Schemaless or flexible models (Key-Value, Document, Wide-Column, Graph).
  • Consistency: Eventual consistency models (BASE) optimized for ultra-high write throughput and partition tolerance.
  • Scaling: Native horizontal scaling out-of-the-box via partition keys and auto-sharding.
  • Queries: Key-value lookups or simple index searches. Multi-document JOINs are either unsupported or inefficient.
NOTE — Decision Rule of Thumb

Choose SQL if you require multi-record ACID transactions, complex relational queries, or your data model is highly structured. Choose NoSQL if you need to scale horizontally to support massive read/write volumes, require flexible document representations, or are storing time-series or unstructured data.

Key Architectural Comparison

Database TypeSchema ModelACID GuaranteesHorizontal ScalabilityBest Fit Workload
SQL (Relational)Strict tabular schema (Foreign Keys).Full ACID out of the box.Challenging (Requires manual sharding/replicas).Financial ledgers, ERP, core order checkouts.
NoSQL (Document)Flexible JSON/BSON documents.Single-document ACID (BASE).Native auto-sharding out of the box.E-commerce catalogs, user profile preferences.
NoSQL (Wide-Column)Partition & Clustering key table.Tunable eventual consistency.Massive linear write scale across petabytes.Time-series telemetry, chat messaging history.
NoSQL (Key-Value)Opaque string or byte values.Atomic single-key mutations.Ultra-fast memory-speed cluster scaling.Session storage, caching, shopping carts.
Next Question When should you choose Vertical Scaling (Scale Up) vs. Horizontal Scaling (Scale Out)?

Continue Learning on Being SDE

Explore deep-dive system architecture modules, low-level object-oriented designs, and interview cheat sheets.