NoSQL Internals
How the four NoSQL families store, spread and copy data, shown through DynamoDB, MongoDB, Cassandra and Neo4j, and how that shapes the way you model data for them.
Overview
NoSQL is a loose name for databases that do not use the relational table model as their main way of storing data. Most of them were built to spread data across many machines from the start, so they give up things that are hard to do across machines, such as joins and multi-row transactions, or make them optional and costly.
There are four main families. A key-value store looks up a value by its key. A document store keeps each record as a nested document, such as JSON. A wide-column store groups rows into partitions and keeps each partition sorted. A graph database stores things and the links between them, and follows those links quickly.
Knowing how each one stores data on disk, spreads it over machines and keeps copies in step explains its rules. It explains why DynamoDB wants you to design keys around queries, why MongoDB prefers embedded documents, why Cassandra writes so fast but deletes are tricky, and why a graph database answers a friends-of-friends query without a join.
What you will be able to do
- Pick the NoSQL family that fits an access pattern, and say what you give up.
- Explain how DynamoDB partitions and replicates a table, and what a GSI costs.
- Walk through Cassandra's write and read paths: commit log, memtable, SSTables, Bloom filters and compaction.
- Explain MongoDB replica sets, write concern and sharding, and when to embed or reference.
- Design keys from a list of queries instead of from an entity diagram.
Key concepts
- Key-value stores
- Document stores
- Wide-column stores
- Graph databases
- Partition and sort keys
- LSM write path
- Replica sets and sharding
- Index-free adjacency
- Query-first modeling
Interview questions
- How does DynamoDB store and replicate data?
- Why are Cassandra writes fast, and what does that cost on reads?
- How would you model a user's orders, newest first, in DynamoDB and in Cassandra?
- Explain MongoDB write concern and what can go wrong with w: 1.
- When would you choose a graph database?
- What is the difference between a GSI and an LSI in DynamoDB?
- How does MongoDB sharding route a query?
- NoSQL databases are said to not support transactions. Is that true?
Sign up free to read the full topic
More Databases & SQL topics
Start free on Cariara · Coding problems · System design studio