What are the main types of NoSQL databases, with examples?
There are four main families of NoSQL databases: key-value stores (Redis, Amazon DynamoDB), document stores (MongoDB, Couchbase), wide-column (column-family) stores (Apache Cassandra, HBase, ScyllaDB) and graph databases (Neo4j, Amazon Neptune). Each uses a different data model optimized for particular access patterns. Time-series and search engines are related specialized stores.
Read full answerHide full answer
Applies toNoSQL database selection and system design
The Four Families
| Type | Data model | Example databases | Best for |
|---|---|---|---|
| Key-value | A key mapped to an opaque value | Redis, DynamoDB, Memcached (cache), Riak | Caching, sessions, counters, simple lookups by ID |
| Document | JSON-like documents with nested fields | MongoDB, Couchbase, Amazon DocumentDB, Firestore | Product catalogues, user profiles, content, varied attributes |
| Wide-column | Rows with a partition key and many sorted columns | Cassandra, ScyllaDB, HBase, Google Bigtable | Write-heavy time series, IoT, event logs at large scale |
| Graph | Nodes and edges with properties | Neo4j, Amazon Neptune, JanusGraph | Social networks, recommendations, fraud rings, network topology |
Note: DynamoDB is often described as both key-value and document, because items can hold nested attributes.
Short Examples
Key-value (Redis)
SET session:9f2a "{\"userId\": 42, \"cart\": 3}" EX 1800
GET session:9f2a
Document (MongoDB)
{"_id": "p1001", "name": "Running Shoe", "price": 89.99,
"sizes": [7, 8, 9, 10], "specs": {"weight_g": 240, "drop_mm": 8}}
Wide-column (Cassandra CQL)
CREATE TABLE sensor_readings ( sensor_id text, reading_time timestamp, temperature double, PRIMARY KEY ((sensor_id), reading_time) ) WITH CLUSTERING ORDER BY (reading_time DESC);
Graph (Neo4j Cypher)
MATCH (u:User {id: 42})-[:FRIEND]->(:User)-[:FRIEND]->(fof:User)
WHERE fof <> u
RETURN DISTINCT fof.name LIMIT 10
Related Specialized Stores
-
Time-series databases (InfluxDB, TimescaleDB, Prometheus storage): optimized for timestamped metrics, downsampling and retention.
-
Search engines (Elasticsearch, OpenSearch): full-text search, relevance ranking, aggregations; usually a secondary store fed from a primary database.
How to Choose
-
Lookups by a single key, very low latency: key-value.
-
Self-contained entities with nested or varied fields, queried by several attributes: document.
-
Huge write volumes with queries by partition and time range: wide-column.
-
Queries that follow many relationships (multi-hop): graph.
Trade-offs
NoSQL stores are designed around known access patterns. Ad-hoc queries, joins and cross-entity constraints are harder than in relational databases. Many NoSQL systems now support transactions (MongoDB multi-document transactions, DynamoDB transactions), but with limits on scope and cost.
Interview Tip
Name the four families, an example database and a typical use case for each, and say that the choice depends on access patterns. A common mistake is saying “NoSQL means no schema and no transactions”; schemas move into the application, and many stores now support transactions.