Types of Databases Explained: SQL, NoSQL and Vector
The main types of databases explained simply: relational, document, key-value, graph, time-series and the vector databases AI uses, with real examples.
- Published
- Reading time
- 8 min read
Contents
- The short answer
- Relational databases (SQL)
- Document databases
- Key-value databases
- Graph databases
- Time-series databases
- Vector databases: the ones AI uses
- SQL vs NoSQL
- Most apps use more than one
- FAQ
- What is the most common type of database?
- What is a vector database in simple terms?
- Do I need a vector database to build an AI app?
- Is MongoDB better than SQL?
- What type of database is Redis?
- Further reading
"Database" used to mean one thing: tables, rows and SQL. Today there are databases built for documents, for caching, for relationships between people, for sensor readings, and for the kind of search that AI tools rely on. They all store data, but each one is shaped for a different question.
This guide explains the main types of databases in plain words: what each one stores, what it's good at, which products you'll meet, and a real example of each. The examples for relational, key-value and vector databases were run on real servers.
Nil's note
I use MySQL every day and we're learning PostgreSQL in class, so relational databases are home for me. This guide is my map of everything else: when a different type of database is worth it, and when a relational one with the right extension is enough.
The short answer
| Type | Stores data as | Best for | Examples |
|---|---|---|---|
| Relational (SQL) | Tables with rows and columns, linked by keys | Most apps: users, orders, anything with relationships | PostgreSQL, MySQL, SQLite, SQL Server |
| Document | JSON-like documents | Data whose shape varies or changes often | MongoDB, Firestore, CouchDB |
| Key-value | A value stored under a key | Caching, sessions, counters, queues | Redis, Valkey, DynamoDB |
| Graph | Nodes and the connections between them | Social networks, recommendations, fraud detection | Neo4j, Amazon Neptune |
| Time-series | Measurements with a timestamp | Metrics, sensors, monitoring | InfluxDB, TimescaleDB, Prometheus |
| Vector | Lists of numbers (embeddings) that capture meaning | Search by similarity, AI chatbots, RAG | pgvector, Pinecone, Qdrant, Chroma |
If you're starting a project and don't know which one you need, the answer is almost always a relational database, and you add another type only when you hit a problem it solves.
Relational databases (SQL)
A relational database stores data in tables. Each row is a record, each column has a type, and tables point to each other with keys: an order has the id of the customer who placed it. You ask questions in SQL, and the database combines tables for you.
SELECT c.name, count(*) AS orders, sum(o.total) AS spent
FROM customers c
JOIN orders o ON o.customer_id = c.id
GROUP BY c.name
ORDER BY spent DESC;
name | orders | spent
------+--------+-------
Ana | 2 | 50
Ben | 1 | 15
Their superpower is consistency: transactions make sure an order and its payment are saved together or not at all, and the schema stops bad data from getting in. That's why they're the default for almost every app.
- PostgreSQL and MySQL are the big open-source servers; see PostgreSQL vs MySQL for how they differ.
- SQLite is a relational database in a single file, with no server; see SQLite vs PostgreSQL.
Document databases
A document database stores each record as a document, usually JSON. A document can contain lists and nested objects, and two documents in the same collection don't need the same fields:
{
"_id": "u42",
"name": "Ana",
"email": "ana@example.com",
"addresses": [
{ "city": "Barcelona", "main": true },
{ "city": "Girona" }
]
}
Everything about Ana lives in one place, so reading her profile is one lookup, with no joins. That fits product catalogs, content management and apps whose data shape changes often.
The trade-off: data that's shared between documents gets duplicated, and keeping copies in sync is your job. MongoDB is the best known; Firestore is common in mobile apps. Relational databases have caught up here too: PostgreSQL's JSONB columns store and index documents inside normal tables.
Key-value databases
The simplest model: you store a value under a key, and get it back by that key. No queries, no joins, just very fast reads and writes, usually from memory.
redis-cli SET session:42 '{"user":"ana"}' EX 3600 # expires in an hour
redis-cli GET session:42 # {"user":"ana"}
redis-cli INCR views:home # 1, then 2, then 3...
That's why key-value stores sit next to a main database rather than replacing it: they cache slow queries, hold login sessions, count page views, limit how many requests a user can make, and run job queues. Redis is the classic choice; Valkey is its open-source fork, and DynamoDB is Amazon's managed key-value database.
Graph databases
A graph database stores nodes (people, products, places) and relationships between them (follows, bought, lives in), and it's built to travel along those relationships quickly. A question like "friends of my friends who like the same band" is natural here:
MATCH (me:Person {name: "Ana"})-[:FRIEND]->()-[:FRIEND]->(fof)
WHERE fof <> me
RETURN DISTINCT fof.name
That's Cypher, Neo4j's query language. In SQL the same question needs a join for every step, and gets slower with each one. Graph databases shine in social networks, recommendations, fraud detection (accounts linked by the same card or device) and knowledge graphs.
Time-series databases
A time-series database stores measurements over time: CPU usage every ten seconds, the temperature of a sensor, the price of a stock. It's optimized to write huge numbers of small, timestamped records, compress them, and answer questions like "average per hour over the last week".
InfluxDB and Prometheus (for server monitoring) are dedicated ones; TimescaleDB adds time-series features to PostgreSQL. If you self-host a monitoring dashboard, there's probably one of these behind it.
Vector databases: the ones AI uses
A vector database stores embeddings: lists of numbers that an AI model produces to capture the meaning of a text, an image or a sound. Texts that mean similar things get similar numbers, even if they don't share a single word. The database's job is to find the vectors closest to the one you give it.
Here's a tiny, real example with pgvector, the extension that turns PostgreSQL into a vector database. Real embeddings have hundreds of dimensions; three are enough to see the idea:
CREATE EXTENSION vector;
CREATE TABLE docs (id serial PRIMARY KEY, text text, embedding vector(3));
INSERT INTO docs (text, embedding) VALUES
('How to adopt a puppy', '[0.9, 0.1, 0.0]'),
('Dog food for young dogs', '[0.8, 0.2, 0.1]'),
('Best electric cars of 2026', '[0.0, 0.9, 0.3]'),
('How to change a car tyre', '[0.1, 0.8, 0.4]');
-- the question "caring for a new dog", turned into a vector
SELECT text FROM docs
ORDER BY embedding <=> '[0.85, 0.15, 0.05]'
LIMIT 2;
text
-------------------------
How to adopt a puppy
Dog food for young dogs
The question doesn't contain "puppy", "food" or "adopt", and a normal LIKE search would find nothing. The vector search finds both dog articles because their meaning is close. <=> is the cosine distance: the smaller, the more similar.
This is the core of RAG, the technique that lets a chatbot answer from your own documents: it turns the question into a vector, finds the closest chunks of your documents, and gives them to the model. RAG explained for developers walks through the whole pipeline.
You don't always need a separate product. pgvector inside PostgreSQL handles millions of vectors and keeps them next to the rest of your data. Dedicated vector databases like Pinecone, Qdrant, Weaviate, Milvus and Chroma make sense at very large scale or when vector search is the main thing your app does.
SQL vs NoSQL
"NoSQL" is the name for everything that isn't relational: document, key-value, graph, wide-column (like Cassandra, built to spread huge amounts of data across many servers) and others. The usual trade:
| Feature | SQL (relational) | NoSQL |
|---|---|---|
| Structure | Fixed schema, checked by the database | Flexible; the app decides |
| Relationships | Joins between tables | Embedded data, or a graph |
| Consistency | Strong, with transactions | Varies; often traded for speed or scale |
| Scaling | Usually one big server, plus read copies | Many are designed to spread across servers |
| Best default for | Most applications | Specific problems at specific scales |
The line is blurrier every year. PostgreSQL stores JSON and vectors, and MongoDB supports transactions. Pick by the problem, not the label.
Most apps use more than one
Real systems often combine types, each doing what it's best at. A typical small SaaS might use:
- PostgreSQL for users, orders and everything that must be correct.
- Redis for sessions, caching and background jobs.
- pgvector in the same PostgreSQL for an AI search feature.
Start with one relational database, and add another type when you can name the problem it solves. If you run them yourself, Docker Compose puts them side by side in one file, and the Docker Compose generator writes it for you.
FAQ
What is the most common type of database?
Relational. PostgreSQL, MySQL, SQLite and SQL Server power most applications, and SQLite alone runs inside almost every phone and browser.
What is a vector database in simple terms?
A database that finds things by meaning instead of exact words. It stores the numbers an AI model gives each piece of text or image, and returns the ones closest to your question. Chatbots that answer from your documents use one.
Do I need a vector database to build an AI app?
Not necessarily. If you already use PostgreSQL, the pgvector extension is enough for most projects. A dedicated vector database makes sense with very large numbers of vectors or when search is your main feature.
Is MongoDB better than SQL?
Neither is better in general. MongoDB is convenient for flexible, document-shaped data; a relational database is safer when data is related and must stay consistent. For a first project, a relational database is the safer default.
What type of database is Redis?
A key-value database that keeps data in memory. It's mostly used next to a main database, for caching, sessions, counters and queues.
Further reading
- pgvector on GitHub
- Redis documentation
- PostgreSQL documentation
- Related: RAG explained for developers
- Related: SQLite vs PostgreSQL
- Related: PostgreSQL vs MySQL
Written by Nil Martinez
Developer · DAM & DAW student
Developer studying multiplatform (DAM) and web (DAW) application development. I work every day with TypeScript, Angular, React, Java, Python, FastAPI, MySQL and Docker on Kubuntu, and I write about the tools I actually use.
Keep reading
PostgreSQL vs MySQL: Differences and Which to Learn
PostgreSQL vs MySQL compared: the SQL that behaves differently, features, licensing and hosting, with every query tested on both and a rule for choosing.
Comparisons10 min read
SQLite vs PostgreSQL: Which Should You Use for Your Project?
An honest comparison of SQLite and PostgreSQL covering performance, concurrency, features, hosting and backups — with a simple rule for choosing.
Comparisons6 min read
FastAPI vs Express: We Built the Same API in Both
FastAPI vs Express with real numbers: the same REST API in both, the code side by side, validation, automatic docs, and a benchmark with one surprising result.
Comparisons9 min read