NoSQL is a name for databases that do not use the relational model. Most of them store data in one of four shapes.
Document
A document store keeps JSON-like documents, grouped in collections. Related data is often embedded in one document:
{ "_id": 101, "status": "delivered",
"customer": { "name": "Ava Chen", "country": "CA" },
"items": [ { "product": "Kraken Plush", "qty": 1 } ] }One read returns the whole order, with no join. Documents in a collection can have different keys. Examples: MongoDB, Couchbase.
The cost: Ava's name is copied into each of her orders. A change must update every copy.
Key-value
A key-value store keeps a value for each key, and finds it only by the key:
session:8f2a → { user 1, cart 3 }
rate:ip:1.2.3 → 17Very fast reads and writes, often in memory. No queries on the contents. Examples: Redis, Amazon DynamoDB (which also has some document features).
Wide-column
A wide-column store keeps rows grouped by a partition key. Each partition is stored together, often on one machine, and sorted by a second key:
partition sensor-17: 09:00 → 21.4 09:01 → 21.5 09:02 → 21.7 …
partition sensor-18: 09:00 → 19.0 09:01 → 19.1 …It spreads huge amounts of data over many machines and writes fast. You design the tables for the queries you will run. Examples: Apache Cassandra, HBase.
Graph
A graph database stores nodes (things) and edges (relationships between them):
A query follows edges from node to node: friends of friends, the shortest route, who can reach what. Examples: Neo4j, Amazon Neptune.
Summary
| Model | Stores | Finds data by | Fits |
|---|---|---|---|
| Relational | tables of rows | any column, joins | most applications |
| Document | JSON documents | keys inside the documents | data read and written as one piece |
| Key-value | a value per key | the key only | caches, sessions, counters |
| Wide-column | rows grouped by partition | partition key and sort key | huge write volumes, time series |
| Graph | nodes and edges | following relationships | networks, recommendations |