Database Types
A tour of the main database families and the access pattern each one was built to serve.
Database types in 30 seconds
- No single database: there's a toolbox, each family shaped around one access pattern.
- The families: relational, key-value, document, wide-column, graph, search engine, time-series — pick by how data is queried.
- OLTP vs OLAP: many small fast operations (live app) versus big analytical scans (warehouse) — keep them separate.
- Columnar storage makes OLAP fast because analytics reads a few columns across millions of rows.
- Polyglot persistence is normal: give each store one job and keep them in sync, often via CDC.
- Choose by query shape, consistency need, and read/write profile — start relational unless an answer says otherwise.
Why a kitchen has more than one knife
A good cook doesn't own one knife — they own a chef's knife, a bread knife, a paring knife, and a cleaver. Each one is shaped for a specific cut, and using the bread knife to peel an apple is clumsy and dangerous even though it technically has a blade. Databases are the same. There's no single 'database' that's best at everything; there's a drawer full of them, each ground to a different edge. The skill isn't knowing every knife by heart — it's recognizing which cut the problem is asking for.
The problem it solves
There's no single 'database' — there's a toolbox of them, each shaped around a specific access pattern. Choosing well means matching the store to how your data is queried, not to what's trendy. This page maps the families so you can recognize which one a problem is pointing at.
The reason the toolbox exists is that a single storage engine can't be great at opposite things at once. A structure that makes reads instant usually makes writes slower; one that spreads writes across a hundred machines usually can't do a join; one that's brilliant at 'find text containing these words' is terrible at 'record this payment safely.' Each family picks a side of those trade-offs on purpose.
The major families
| Family | Data shape | Shines at | Struggles with | Example use |
|---|---|---|---|---|
| Relational | Tables with a schema + joins | Correctness, complex queries, transactions | Horizontal write scale | Orders, payments, anything transactional |
| Key-value | key -> opaque value | Fast lookups by key | Querying by non-key fields | Sessions, caches, feature flags |
| Document | key -> JSON-like document | Flexible, nested records | Cross-document joins/transactions | Profiles, catalogs, CMS |
| Wide-column | Partitioned rows, dynamic columns | Huge write throughput, time-series | Ad-hoc queries | Event logs, metrics, feeds |
| Graph | Nodes + edges | Relationship traversal | Bulk scans, sharding | Social graph, recommendations, fraud |
| Search engine | Inverted index of documents | Full-text search, ranking, facets | Being the source of truth | Product search, log search |
| Time-series | Timestamped points | Append-heavy metrics over time | Updates/deletes of old data | Monitoring, IoT, finance ticks |
Relational — the default you should beat before leaving
The relational database is the sensible starting point for almost everything. Data lives in tables with a fixed, enforced schema; related tables link by id; and you recombine them on demand with joins, all wrapped in ACID transactions. That combination means it answers questions nobody anticipated and keeps your data from contradicting itself. Its one real weakness is scaling writes past a single leader — which is exactly the pressure that pushes systems toward the other families.
-- Combine two tables AND change state safely, atomically:
BEGIN;
INSERT INTO orders (id, user_id, total) VALUES (991, 17, 42.00);
UPDATE inventory SET stock = stock - 1 WHERE sku = 'A-1';
COMMIT; -- both happen, or neither does
-- Then ask an unplanned question with a join -- no pre-planning needed:
SELECT u.name, SUM(o.total) AS spent
FROM users u JOIN orders o ON o.user_id = u.id
GROUP BY u.name;Key-value — the giant dictionary
A key-value store is conceptually a huge dictionary spread across many machines: you hand it a key, it hands back the value, and that's the whole API. There's no schema and no join — which is precisely why it's blisteringly fast and scales out so easily. The trade is absolute: if you don't know the exact key, you can't find the value.
# Fast, dead-simple: you reach data only by its key
kv.put("session:9f2c", {"user": "ada", "exp": 1699999999})
session = kv.get("session:9f2c") # O(1)-ish lookup
# There is no "find all sessions for user ada" here —
# querying by a non-key field is exactly what this family can't do.Document — flexible records, read in one hit
A document store keys a whole JSON-like object, so each record can carry nested data and vary shape from the next. Because a document holds everything a screen needs, you read it in a single lookup — no join. You pay for that by denormalizing (duplicating data), which means an update may have to touch many documents. It shines when records are self-contained and the schema keeps evolving.
// One document carries everything the profile page needs —
// no join, one read. Fields can differ from the next document.
{
"_id": "user_17",
"name": "Ada",
"addresses": [ // nested array, no separate table
{ "label": "home", "city": "London" },
{ "label": "work", "city": "Cambridge" }
],
"prefs": { "theme": "dark" } // this user has prefs; others may not
}Wide-column and graph — writes at scale vs relationships
Wide-column stores partition rows across nodes and let each row have a different set of columns. They're built to swallow enormous write volume — event logs, metrics, feeds — by making writes a cheap append and keeping related data physically together. Graph databases do the opposite kind of job: they store nodes and the edges between them, and make 'hop from this node to connected ones' near-constant per hop. The same friends-of-friends question that explodes into painful self-joins in SQL is the graph database's home turf.
// Walk relationships, not rows. Cypher-style traversal:
MATCH (me:User {id: "ada"})-[:FRIEND]->()-[:FRIEND]->(fof:User)
WHERE NOT (me)-[:FRIEND]->(fof) AND fof <> me
RETURN DISTINCT fof.name
// The engine hops edge-to-edge in near-constant time per hop —
// the same query as self-joins in SQL gets painful past 2-3 hops.Search engine and time-series — specialized readers
Two more families each solve one question extremely well. A search engine builds an inverted index — a map from each word to the documents that contain it — so 'find everything mentioning rocket, ranked by relevance' is instant. It's a fantastic reader but a poor source of truth, so you keep your real data elsewhere and feed changes into it. A time-series database is tuned for append-only, timestamped points (CPU usage every second, stock ticks), where you almost never update old data and you mostly ask 'what happened between 2pm and 3pm?'
The other axis: OLTP vs OLAP
A separate axis cuts across families. OLTP stores (most of the above) handle many small, fast reads and writes — the live application. OLAP stores (data warehouses, columnar engines) handle big analytical scans over huge datasets — dashboards and reports. You don't run heavy analytics on your transactional database; you pipe data into a warehouse so the two workloads don't fight. Columnar storage makes OLAP fast because analytics reads a few columns across millions of rows, not whole rows.
// Row store (OLTP): one row = all its columns together on disk.
// [id,name,age,city,signup] [id,name,age,city,signup] ...
// Great for "give me THIS whole row."
// Column store (OLAP): each column stored together.
// ages: [34, 29, 41, 55, ...] signups: [2021, 2022, ...]
// "average age of 50M users" reads ONLY the ages column ->
// it skips 90% of the bytes a row store would have to scan.The gap any single store can't fill
A tempting shortcut is 'just put everything in one database to keep it simple.' It fails for the same reason the bread knife fails at peeling: one engine can't be optimized for opposite jobs. Force full-text search onto a relational database and keyword queries crawl; run analytics on your transactional store and the dashboard query locks up live traffic; push a billion sensor writes into a single relational leader and it topples. The simplicity of one store is real, but it evaporates the moment two access patterns pull in opposite directions.
How to choose, quickly
Ask three questions: How is this data queried? (by key, by relationship, by full text, by time range), What consistency does it need? (strong for money, eventual for feeds), and What's the read/write profile? (read-heavy, write-heavy, append-only). The answers usually point straight at a family. Start relational unless one of those answers clearly says otherwise.
| The question you ask most | Points to | Why |
|---|---|---|
| Change state safely across entities | Relational | ACID transactions + joins. |
| Get/put one value by a known key, fast | Key-value | No schema, no join, scales out. |
| Fetch a whole self-contained record | Document | Nested data read in a single hop. |
| Absorb a firehose of writes | Wide-column | Writes are cheap appends; partitioned. |
| Traverse relationships | Graph | Edge hops instead of exploding joins. |
| Find documents by their text | Search engine | Inverted index ranks matches instantly. |
| Scan metrics over a time range | Time-series | Append-only, time-partitioned storage. |
| Crunch analytics over millions of rows | OLAP / columnar | Reads only the few columns it needs. |
Knowing the database families isn't trivia — it's the vocabulary for matching each workload to the store built for it, which is what keeps a growing system from bending one database into shapes it was never meant to hold.
Why it matters
- Recognizing the right family turns a vague 'where do we put this?' into an obvious call.
- It's what lets a big system run several stores well instead of one store badly.
- Separating OLTP from OLAP keeps analytics from starving the live application.
If ignored
- You force every access pattern through one database and fight it on the ones it handles poorly.
- Heavy analytics runs on the transactional store and drags live traffic to a crawl.
- You confuse the source of truth with a search or analytics index and let them drift out of sync.
Where it fits
- Sits at the data layer, deciding which store backs each capability.
- Shows up as polyglot persistence, with CDC piping changes between stores.
- Feeds directly into indexing, replication, and scaling decisions downstream.
Related topics
- SQL vs NoSQL: the first fork this toolbox expands on
- Indexing: how each family makes its chosen access pattern fast
- Pub/sub & CDC: the plumbing that keeps polyglot stores in sync
- Database scaling: what to do when the family you chose starts to buckle
Interview lens
Questions it unlocks
- What type of database fits this workload?
- Why not just use one database for everything?
- Where would full-text search or analytics live in your design?
60-second answer
I choose a database by access pattern: relational for transactional truth and complex queries, key-value for fast keyed lookups, document for flexible nested records, wide-column for massive write/time-series throughput, graph for relationship traversal, a search engine for full-text, and a warehouse for analytics. I separate OLTP from OLAP so analytics doesn't starve the live app. Polyglot persistence is expected — each store gets one job, kept in sync via CDC. For semantic search I'd add a vector store alongside, not instead of, the others.
Common traps
- Forcing one database to serve every access pattern.
- Running heavy analytics on the transactional (OLTP) database.
- Treating the source of truth and the search index as the same thing.