NoSQL Data Stores
Transcript
Made automatically from the video's sound, so it may contain mistakes. Click a line to play from there.
Right, let's dive straight into this explainer. Building on our one sentence recap of episode 2's analytical lakehouses, we are now shifting gears back to the operational data tiers. This is where we trade the comforting safety of general purpose SQL for extreme raw scale, fundamentally changing how we actually think about storing and retrieving our application's most critical data.
Here's the roadmap for mapping out today's NoSQL landscape. We'll be covering one, the relational migration trap, two, inside the four engines, three, query first data modeling, four, production failure cliffs, and five, the final decision matrix.
The relational migration trap. Let's look at a scenario that has burned countless engineering teams. A team decides Postgres is bottlenecking, so they just lift and shift highly normalized tables straight into a NoSQL store.
But because NoSQL drops traditional SQL joins, the application network layer takes the hit. The app is forced to piece relationships together itself, resulting in N plus one scatter gather queries over the network that routinely blow past 500 milliseconds in latency.
It's an absolute architectural anti-pattern, and frankly, a massive performance killer. Inside the four engines. First up, we've got key value stores.
With Redis, you get consistent sub millisecond lookups, purely because data sits entirely in memory, partitioned across exactly 16,384 RAM hash slots, which is then backed by snapsotting and append-only files for durability. By the way, if you really want to geek out on Redis Eviction internals, definitely cross reference our web architecture explainer, season two, episode seven.
Now, on the persistent side, DynamoDB relies on partition and sort keys hashed against a Veno token ring to distribute your data globally. Moving on to the document family. MongoDB is your classic heavyweight here, running on its Wired tiger storage engine, which is actually based on B trees.
It manages hierarchical BSON data using ranged or hashed sharded chunks. Now, while Wirediger gives you excellent document level concurrency control, you have to be highly strategic with your shard keys. If you aren't, you'll end up with scattergather queries across your cluster, which will absolutely ruin your overall throughput.
Then we have the wide column family. Think Cassandra and SkylarDB. This is defined by its log structured merge, or LSM tree design. To absorb massive constant write throughput, random writes are just eliminated.
Instead, writes are sequentially appended to a commit log on disk and then kept in a RAM mem table. Once that's full, it flushes to disk as an immutable SS table. Because you literally never update in place, you rely heavily on Bloom filters to rapidly check if a key even exists before committing to a read operation.
What's really fascinating here is the stark architectural contrast in how these engines are actually built. Apache Cassandra runs on the Java virtual machine. The engineering trade-off there is the occasional dreaded P99 latency tail spike caused by JVM garbage collection pauses.
ScyllaDB saw this and totally rewrote the architecture in C using a shared nothing shard per core design, completely eliminating those unpredictable GC pauses. Finally, graph databases like Neo4J, they ditch relational joins entirely for a brilliant concept called native index free adjacency.
Basically, every node maintains direct physical RAM pointers to its adjacent relationships, giving you constant O of one pointer hops. So where a relational database would just choke and die on a recursive five-hop join, a graph database traverses millions of deep connections in milliseconds.
Query first data modeling. To actually leverage these incredibly powerful internal mechanics, you have to throw third normal form right out the window. Query first denormalization means you stop modeling entities and you start designing schemas backward from the exact queries your UI requires.
You pre-compute your joins at right time, happily duplicating data if necessary, strictly to keep related bytes sitting physically next to each other on disk. For instance, in a document store like MongoDB, you're constantly weighing the trade-offs of embedding versus referencing.
Bounded document embedding shoves all related data into a single document for incredibly fast single reads. But if that embedded array grows infinitely, you will hit a wall. Referencing avoids this by keeping documents small, but it immediately forces you back into doing multiple network lookups.
Your access pattern completely dictates this choice. Meanwhile, wide column and key value stores enforce even harsher realities. DynamoDB routinely forces you into single table designs, where you're overloading generic partition and sort keys to satisfy a dozen access patterns in one table, augmented by global secondary indexes.
Cassandra is even stricter. It demands at one table per query model, governed by clustering column orders. If you need to filter the exact same data three different ways, you are writing it to three entirely different tables, no exceptions.
Production failure cliffs. Here's a classic pager duty nightmare for you. The DynamoDB hot partition. Imagine a viral event where all user traffic suddenly hits a single partition key.
Dynamo DB will brutally throttle your application if that hot partition exceeds 1,000 write capacity units or 3,000 read capacity units. To survive this, you're forced to implement application side write sharding. You are literally appending random suffixes to your keys just to artificially spread that data across the hashing ring.
Some other concrete failure cliffs you definitely need to memorize include Cassandra's handling of deletes. It uses tombstones. If you scan over 100,000 tombstones, you'll store reads and blow up your JVM heap.
Not to mention the compaction amplification nightmare of tuning STCS versus LCS or TWCS. In MongoDB, you must respect the strict 16 MB BSON limit, or your unbounded arrays will crash the right.
And in Neo4J, traversing a celebrity supernode with millions of edges will cause exponential RAM explosions. This brings us to a rather harsh truth from software architect Martin Fowler. The idea of the schemaless database is a complete myth.
You always have a schema. By not enforcing it at the database level, you are simply shifting the massive burden of schema migration debt and all its nasty edge case bugs directly into your application code.
The final decision matrix. Let's pull all of these engineering realities together. The quantified engineering rule of thumb here is remarkably conservative. Stay on our baseline Postgres JSON B setup.
Why? Ultimate flexibility. You really only migrate to these specialized engines if your right throughput, your need for tunable R plus W greater than N quorum consistency over Raft, your demand for five hop deep graft reversals, or your strict sub-millisecond RAM lookups absolutely force your hand.
But if you do make the jump, you'll end up with highly denormalized data scattered across all these blazing fast engines, and that leaves a massive, terrifying architectural void. How exactly do you keep highly denormalized views safely in sync across systems without the safety net of distributed SQL transactions?
Well, we are going to solve that exact architectural trap next time when we tee up episode four on streaming and event driven data. See you then.