Skip to content
DevPlainly
Comparisons

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
  1. The short answer
  2. Relational databases (SQL)
  3. Document databases
  4. Key-value databases
  5. Graph databases
  6. Time-series databases
  7. Vector databases: the ones AI uses
  8. SQL vs NoSQL
  9. Most apps use more than one
  10. FAQ
  11. What is the most common type of database?
  12. What is a vector database in simple terms?
  13. Do I need a vector database to build an AI app?
  14. Is MongoDB better than SQL?
  15. What type of database is Redis?
  16. 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

TypeStores data asBest forExamples
Relational (SQL)Tables with rows and columns, linked by keysMost apps: users, orders, anything with relationshipsPostgreSQL, MySQL, SQLite, SQL Server
DocumentJSON-like documentsData whose shape varies or changes oftenMongoDB, Firestore, CouchDB
Key-valueA value stored under a keyCaching, sessions, counters, queuesRedis, Valkey, DynamoDB
GraphNodes and the connections between themSocial networks, recommendations, fraud detectionNeo4j, Amazon Neptune
Time-seriesMeasurements with a timestampMetrics, sensors, monitoringInfluxDB, TimescaleDB, Prometheus
VectorLists of numbers (embeddings) that capture meaningSearch by similarity, AI chatbots, RAGpgvector, 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.

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:

FeatureSQL (relational)NoSQL
StructureFixed schema, checked by the databaseFlexible; the app decides
RelationshipsJoins between tablesEmbedded data, or a graph
ConsistencyStrong, with transactionsVaries; often traded for speed or scale
ScalingUsually one big server, plus read copiesMany are designed to spread across servers
Best default forMost applicationsSpecific 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

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.

How I test and write each guideGitHub

Keep reading