The NoSQL Landscape
You'll learn to
- -Name the four NoSQL data models and the shape of data each one fits
- -Say what NoSQL gives up and what it gains compared with SQL
- -Show with numbers why friends-of-friends queries are awkward in SQL and natural in a graph
- -Explain why LSM-trees make writes fast, and what that costs on reads
A relational database makes strong promises, and those promises have a price: every row in a table must fit one fixed shape, and keeping its guarantees across many machines is hard. As a product grows you may need something the relational model is not best at: data whose shape varies from record to record, an enormous volume of simple reads or writes, or relationships that run many steps deep. NoSQL (often read as not only SQL) is a family of databases that each relax something the relational model insists on, in exchange for doing one kind of job very well. There is no single NoSQL model, so the real skill is knowing the four main shapes and what each is for.
An Analogy: Four Ways to Store Belongings
Picture four different places to keep your things. A coat check hands you a numbered ticket: give the ticket, get your coat in an instant, but nobody can ask the attendant for every red coat. A drawer of personal folders holds one folder per person, and each folder contains whatever papers that person happens to have, so no two folders need the same contents. A huge ledger sorted by account number lets every row grow its own extra columns, and the bookkeeper is built to add new lines at tremendous speed. And a corkboard with pins and string shows who knows whom, so finding a friend of a friend means following two strings.
- -The coat check is a key-value store (Redis, DynamoDB): the fastest possible lookup by key, but you can only look up by key, not by what is inside the value.
- -The drawer of folders is a document store (MongoDB, Firestore): one self-describing JSON-like record per entity, so records can differ in shape.
- -The sorted ledger is a wide-column store (Cassandra, HBase): rows found by key, each with its own sparse set of columns, built for a very high rate of writes.
- -The corkboard is a graph database (Neo4j, Neptune): the connections are stored as first-class data, so following them is cheap.
A Document Is a Whole Entity in One Place
The easiest contrast with SQL is a user profile whose shape varies. In a relational design, addresses, phone numbers and preferences would each be spread across their own tables and joined back together. A document store keeps the whole entity as one record, which can be read or written in a single step:
{
"id": 42,
"name": "Asha",
"addresses": [{ "type": "home", "city": "Pune" }],
"preferences": { "theme": "dark" }
}The trade-off is the mirror image of SQL's: a flexible shape and one-step reads, but limited joins across documents, and keeping several documents consistent with each other is largely your job.
Why Graphs Exist: Friends of Friends
The graph model is the one whose reason to exist can be shown with arithmetic. Suppose each person has 200 friends and you want everyone within three steps. In SQL that means joining the friendship table to itself, and each extra step multiplies the work: 200 friends, then about 200 times 200 = 40,000 friends of friends, then about 200 times 200 times 200 = 8,000,000 candidates at three steps (before removing duplicates). Both approaches have to visit the people in range. The graph database's advantage is that each hop follows a stored link instead of searching a table of millions of rows, so its cost depends on the size of the neighborhood rather than on the size of the whole data set.
What You Give Up, and What You Get
- -You get horizontal scale: data is divided by key and designed to spread across many machines.
- -You get a flexible schema: records can change shape without migrating a whole table.
- -You get speed on the one access pattern the model was built for.
- -You give up ad hoc queries: you design for your access patterns up front, and asking a new kind of question can mean restructuring the data.
- -You usually give up joins, and often transactions that span several records (this varies by product).
Many NoSQL products have narrowed this gap over the years, so check what a specific product guarantees rather than assuming. The honest summary is that NoSQL is not faster than SQL in general: it is faster at one pattern because it gave something up. For a side-by-side comparison with concrete scenarios, the card below sets the two against each other:
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.
Where That Write Throughput Actually Comes From: LSM-Trees
Imagine taking notes in a meeting. Jotting each point at the bottom of a scratch pad is instant, whereas tidying every point into its proper place in a bound notebook as it arrives would slow you down. So you scribble fast, and when the pad is full you copy it out in one sweep, neatly sorted, as a new sealed page. That is an LSM-tree: the scratch pad is the memtable, and each sealed, sorted page is an SSTable.
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.
Run the simulation below and watch writes pile up in the memtable, then flush to disk as one sorted file, without anything ever being updated 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.
Discussion0
Join the Discussion
Sign in to leave comments, reply to others, or like insights.
No comments yet. Be the first to start the thread!