
Last updated: December 3, 2026
Most database advice is a list of product names. This one is about shapes of data instead, because that is what you are really choosing between. Once you know whether your data is tables, documents, keys, a graph or a stream of measurements, the product shortlist gets short.
If you only want a default: use a relational database, and for most new projects that means PostgreSQL, or SQLite for something small or local. The rest of this guide explains when to leave that default, and when not to.
The short answer
What a database is, and what the engine does for you
A database is organized data stored so that programs can read and change it quickly and safely. The software that does the work is a database management system, or DBMS. It handles storage on disk, lets many users read and write at once, enforces rules about what data is valid, and recovers after a crash. When people say "the database" they usually mean the data and the DBMS together.
The key word in that list is safely. A spreadsheet or a plain file can hold the same rows, but it will not stop two users from overwriting each other, and it will not refuse a bad value. That gap is why applications use a database instead of a file once more than one person or process touches the data.
The main families, side by side
| Family | Examples | Good at | Watch out for |
|---|---|---|---|
| Relational (SQL) | PostgreSQL, MySQL, SQLite, SQL Server | Structured data with relationships, transactions, reporting with joins | Changing the table design after the fact takes planning |
| Document | MongoDB | Records that vary in shape and are read as a whole, such as content or product catalogs | Relationships across documents are more work than a SQL join |
| Key-value / in-memory | Redis | Caches, sessions, counters, queues: very fast lookups by key | Not a place to run ad hoc queries over everything; memory is limited |
| Graph | Neo4j | Data where the connections are the point: recommendations, networks, fraud rings | A niche tool; overkill when relationships are simple |
| Time series | InfluxDB | Metrics and sensor readings with a timestamp on every row | Poor fit for general application data |
| Warehouse / columnar | BigQuery, Snowflake | Analytics over very large datasets | Built for reading in bulk, not for serving an app one row at a time |
Relational: tables, keys and joins
A relational database stores data in tables of rows and columns and links tables with keys. You query it with SQL, a language standardized by ISO that every major relational system implements in large part. Here is the same small library modeled the relational way: one table of authors, one of books, linked by author_id.
import sqlite3
con = sqlite3.connect(":memory:")
con.executescript("""
CREATE TABLE authors (id INTEGER PRIMARY KEY, name TEXT NOT NULL);
CREATE TABLE books (
id INTEGER PRIMARY KEY,
author_id INTEGER NOT NULL REFERENCES authors(id),
title TEXT NOT NULL,
year INTEGER
);
INSERT INTO authors VALUES (1, 'Ursula K. Le Guin'), (2, 'Octavia E. Butler');
INSERT INTO books VALUES (1, 1, 'The Dispossessed', 1974),
(2, 1, 'A Wizard of Earthsea', 1968),
(3, 2, 'Kindred', 1979);
""")
sql = """SELECT authors.name, books.title, books.year
FROM books JOIN authors ON authors.id = books.author_id
ORDER BY books.year"""
for row in con.execute(sql):
print(row)
# ('Ursula K. Le Guin', 'A Wizard of Earthsea', 1968)
# ('Ursula K. Le Guin', 'The Dispossessed', 1974)
# ('Octavia E. Butler', 'Kindred', 1979)
That output is what SQLite returned when this was run. The author's name is stored once. Rename her and every book reflects it. The REFERENCES clause means the database will not let you add a book for an author that does not exist. That is the safety the engine gives you for free. If you want to learn the query language itself, start with our SQL for beginners guide.
Document: one record, one self-contained object
A document database stores each record as a self-describing object, usually JSON-like. MongoDB, for example, stores records as BSON documents, a binary form of JSON with extra data types. The same data as one document per author looks like this:
{
"name": "Ursula K. Le Guin",
"books": [
{
"title": "A Wizard of Earthsea",
"year": 1968
},
{
"title": "The Dispossessed",
"year": 1974
}
]
}
Reading an author and all their books is a single fetch with no join. That is the appeal. The cost shows up when the same data is needed from the other side. If you also want "every book from 1974", the book titles are now buried inside author documents, and a book that has two authors has to be copied or referenced by hand. Document databases fit data that is naturally read as a unit and rarely sliced across records.
One thing worth knowing before you choose a document store for flexibility: relational databases have caught up on this front. PostgreSQL has json and jsonb column types, so you can keep a flexible blob inside an otherwise structured table.
Key-value and in-memory: speed for simple lookups
Redis describes itself as an in-memory data store used as a cache, a message broker and more. You give it a key, you get a value back, in memory, which is far faster than a disk-backed query. The usual pattern is not to replace your main database but to sit beside it: cache an expensive result, store a login session, or count requests per minute. Treat it as a speed layer, not as the system of record.
Graph, time series and warehouses: the specialists
- Graph. Neo4j is a native graph database: it stores nodes and the relationships between them directly, and you query paths with its Cypher language. Choose it when the question is "how are these things connected, and through how many hops". Questions like "friends of friends who bought this" are awkward as repeated joins and natural as a graph walk.
- Time series. Systems like InfluxDB are built for data that is a timestamp plus a measurement, arriving constantly, such as server metrics or sensor readings. They are designed around that shape, with features for compressing and expiring old data.
- Warehouses. BigQuery and Snowflake store data by column so that analytical queries scanning millions of rows are fast. They are for reports and analysis, not for the database behind your sign-up form.
The embedded option: SQLite
SQLite is a different kind of relational database. It has no server: the whole database is a single file read directly by your program. Its own documentation says it does not compete with client/server databases; it competes with fopen(). It is a good fit for apps, tools, tests and small sites, and a poor fit when many machines need to write to the same data at once. Our SQLite and Python expense tracker is a worked example.
How to choose
Work through these questions in order and stop at the first clear answer.
- Is it a small app, a script or a local tool? SQLite.
- Is it a typical web or business application with users, orders, accounts and reports? PostgreSQL or MySQL. Pick the one your team and host already support well.
- Do you need very fast reads for the same lookups, over and over? Add Redis next to your main database as a cache.
- Is the data mostly whole objects with changing fields, and you rarely query across them? A document database is reasonable. Check first whether a JSON column in PostgreSQL does the job.
- Is the central question about connections? Look at a graph database.
- Is it a firehose of timestamped measurements, or analytics over huge history? A time-series database or a warehouse.
Licensing and hosting: two things to check early
Open source is not one thing. PostgreSQL is released under the PostgreSQL License, a permissive license similar to BSD or MIT. Other systems use copyleft or source-available licenses with different conditions for commercial use or for offering the software as a service. Read the license before you build a product on top of a database, and check whether you want to run it yourself or pay a cloud provider to run it. Running a database means backups, upgrades and security patches, and a managed service takes those off your plate for a fee.
Whichever you choose, take backups and test restoring them. A backup you have never restored is a hope, not a backup.
Where to go next
- SQL for Beginners: The Core Commands, With Examples You Can Run
- SQLite with Python: build a real expense tracker
We'd love to hear your thoughts! Leave a comment below
and share your experience or questions.