The NoSQL Landscape
You'll learn to
- -Name the four main NoSQL data models
- -Know when NoSQL beats SQL and vice versa
- -Explain why LSM-trees give wide-column stores their write throughput
SQL's rigidity is a feature, until it becomes a bottleneck. A rigid schema means every write has to fit the same shape, and a single table's guarantees get harder to maintain the moment you need to split that table across multiple machines (a problem the next module tackles directly). NoSQL databases relax exactly this rigidity in exchange for horizontal scalability.
SQL = structured, relational, ACID-strong transactions. NoSQL = flexible, horizontally scalable, varied consistency models.
SQL is like a perfectly organized filing cabinet with labelled folders, cross-references, and mandatory forms. NoSQL is like a giant bin - you can throw anything in instantly, find things by key quickly, but complex "find everything related to X" queries require custom work.
SQL (Relational Databases) organize data into tables with rigid schemas. Data integrity is enforced by FOREIGN KEY constraints, NOT NULL, and UNIQUE checks. They guarantee ACID properties: Atomicity (all-or-nothing), Consistency (rules are never violated), Isolation (concurrent transactions don't interfere), Durability (committed writes survive crashes).
SQL's JOIN operation is the superpower: intricate queries linking dozens of tables in one round trip. This is perfect for e-commerce (orders + users + products + inventory all joined), banking (accounts + transactions + balances), or any domain with complex relationships.
NoSQL Databases trade strict schemas and JOINs for horizontal scalability and flexible data models. There are 4 main types: Key-Value (Redis, DynamoDB), Document (MongoDB, Firestore), Wide-Column (Cassandra, HBase), and Graph (Neo4j, Neptune).
NoSQL scales horizontally almost effortlessly because data is already partitioned by key - no need to coordinate complex JOIN operations across nodes. Writing 1 million events/second to Cassandra is straightforward; doing the same to Postgres requires extreme engineering.
The myth is "NoSQL is always faster." The truth: NoSQL wins on write throughput and simple key-based reads. SQL wins on complex queries, ad-hoc reporting, and systems requiring strict consistency. Many mature systems use both: Postgres for core business data, Redis for caching, Cassandra for time-series events.
- -Use SQL for: financial transactions, user accounts, inventory - anywhere ACID matters.
- -Use NoSQL for: time-series data, user activity feeds, caches, unstructured content.
- -NoSQL is NOT automatically faster - it trades query expressiveness for write throughput.
- -Schema-on-write (SQL) vs Schema-on-read (NoSQL Document stores).
- -NoSQL eventual consistency is a feature, not a bug - for the right use case.
Quick Reference: The Four Models
- -Key-Value: a giant hash map (Redis, DynamoDB). Fastest possible lookups by key, no querying by value.
- -Document: JSON-like nested records (MongoDB, Firestore). Flexible schema, good for content that varies shape between records.
- -Wide-Column: rows with dynamic, sparse columns grouped into families (Cassandra, HBase). Built for massive write throughput.
- -Graph: nodes and edges as first-class citizens (Neo4j, Neptune). Built for traversal queries like "friends of friends" that would need many expensive joins in SQL.
Where That Write Throughput Actually Comes From: LSM-Trees
The B-tree index from the last chapter is read-optimized: it keeps data sorted on disk at all times, so every write has to find the right spot and update it in place, which means random disk I/O. Wide-column stores like Cassandra and HBase, along with embedded engines like RocksDB and LevelDB, use a different structure entirely to get their write throughput: the Log-Structured Merge-Tree, or LSM-tree.
An LSM-tree never updates data in place. Every write is first appended to an in-memory, sorted structure called a memtable, an operation that costs no disk I/O at all. Once the memtable fills up, it is flushed to disk as a new, immutable, sorted file called an SSTable (Sorted String Table), and a fresh, empty memtable takes over for new writes. Because a flush writes one large sequential block instead of many scattered updates, it is dramatically cheaper than the random writes a B-tree needs to keep itself sorted in place.
The LSM-Tree Write Path
Ten writes, a memtable capacity of 4, and the flush and compaction events that follow.
Memtable (in memory)
Disk (immutable SSTables)
Every write starts here: appended to the memtable, a sorted in-memory structure. No disk I/O yet, this is why LSM-tree writes are so fast.
The cost shows up on reads instead. A single key might exist in the memtable, or in any of several SSTables on disk (whichever one was current when it was last written), so a lookup may have to check multiple places, newest first, until it finds the key. A background compaction process periodically merges older SSTables together, both to reclaim space taken by overwritten or deleted keys and to bound how many separate files a read ever has to check.
This is the same read-versus-write trade-off that shows up everywhere in this course, just at the storage-engine layer: a B-tree optimizes for fast, in-place reads at the cost of expensive random writes. An LSM-tree optimizes for fast, sequential writes at the cost of a read sometimes needing to check several files instead of one.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.