DatabasesDeeper

Kayavak / Databases / DB·62 NoSQL Data Models and Stores / Deeper

Deeper · Databases

NoSQL Data Models and Stores

The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.

Why does this exist?

In the late 2000s large web companies needed things relational databases of the time didn't offer easily: writes spread across hundreds of machines, staying available through failures and network partitions, and data whose shape changed weekly. Google's Bigtable (2006) and Amazon's Dynamo (2007) papers described in-house answers; open-source systems followed (Cassandra from Facebook in 2008, MongoDB in 2009, HBase, Redis). The name NoSQL came from a 2009 meetup hashtag, and was later reinterpreted as "not only SQL".

Each traded away something relational databases gave: joins, multi-row transactions, enforced schemas or immediate consistency. Analytics took another path: column stores (C-Store in 2005, then Vertica, and later ClickHouse, BigQuery and others) store each column together and scan billions of rows fast. Over time the lines blurred: relational databases added JSON and horizontal scaling, and NoSQL stores added transactions and SQL-like languages.

The mental model

Try it yourself first: write your own model in the Mental Model Explorer, then compare.

A NoSQL store is designed around specific access patterns. You model data for the queries you'll run, not for the facts you'll store, and accept that questions you didn't plan for may be expensive or impossible.

Question Answer
What is it? Non-relational data stores: key-value, document, wide-column, graph, time-series and column-oriented analytics
Problem it solves Scale, availability, flexible shapes or specialised operations a general relational design handles poorly
Parts Data models, partition and clustering keys, replication and quorums, consistency levels, secondary indexes
How it works Data is partitioned by key across nodes; each access pattern maps to a key lookup or a range within a partition
Assumptions Access patterns are known in advance and stable
When they change A new query that doesn't follow the partition key becomes a scan of the whole cluster
Where it fails Ad-hoc questions, multi-entity invariants, and data duplicated across documents drifting apart
Related ideas Relational modelling (ch55); quorums and consistency (Distributed Systems); analytics engines (Data Engineering)

What if?

What if product managers ask a new question of a Cassandra table?

Reason it through, then open

If it isn't answerable from the partition key, it needs a full scan across nodes (which Cassandra discourages), a new table holding the data arranged for that query, or a secondary index with its own costs. Query-first design is the deal: excellent for known patterns, expensive for new ones. Relational databases handle unplanned questions with a new query.

What if you read and write with quorums where R + W > N?

Reason it through, then open

With N replicas, writing to W of them and reading from R guarantees the read set overlaps the latest write's set, so a read sees the latest acknowledged write (given no concurrent failures muddying it). With N = 3, R = W = 2 gives that overlap while tolerating one replica down. Lower R or W trades the guarantee for latency and availability.

Where the boundary is

Aspect Row store (OLTP) Column store (OLAP)
Stores together All columns of a row All values of a column
Fast at Reading and writing whole rows by key Scanning a few columns over many rows
Compression Modest Very high: similar values sit together
Use for Applications Analytics and reporting

How sure are we?

Claim How it's known Where from
"NoSQL" named at a 2009 meetup Historical Johan Oskarsson's event in San Francisco
R + W > N gives overlapping quorums Theorem Quorum intersection; sloppy quorums and concurrent writes weaken it
Column stores are much faster for analytics scans Measured C-Store (2005) and many benchmarks since

Still open

Whether general-purpose relational databases with extensions will absorb most specialised workloads (documents, time series, vectors) or specialised stores will keep winning is a live, workload-by-workload argument.

What would change your mind? If your access patterns were stable and your scale demanded horizontal writes, a purpose-built store would be the right default; otherwise a relational database usually is.

Recall

What's the main design rule for a NoSQL data model?

Design for the access patterns (queries) you know you'll run.

Why do column stores suit analytics?

Scans read only the needed columns, and similar values compress well.

What does R + W > N guarantee?

Every read quorum overlaps the latest write quorum, so reads see the latest acknowledged write.

What do NoSQL stores typically give up?

Some of joins, multi-entity transactions, enforced schemas or immediate consistency.

Reflect

Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.