Types of databases: SQL vs NoSQL, Redis, graph and more
Relational, document, key-value, wide-column, graph, time-series and search engines. How each one stores data, what it's good and bad at, real examples, and how to pick (or combine) them in a system design.
In one sentence
Each database type is optimized for a different shape of data and access pattern. Pick by the questions you need to answer fast, not by fashion.
Same data, different shapes
The easiest way to understand database types is to store the same thing in each of them. Here it's a user called Ana, her orders and the people she follows.
users
id | name1 | Ana
2 | Bob
orders
id | user_id | total91 | 1 | 30.00
92 | 1 | 12.50
ExamplesPostgreSQL, MySQL, SQL Server, Aurora
Strong at
- + Joins across tables
- + ACID transactions
- + Strict schema and constraints
Weak at
- − Sharding is hard
- − Schema changes on huge tables
Reach for it whenYour data has clear relations and correctness matters: payments, orders, users.
SQL vs NoSQL
"NoSQL" isn't one thing: it's every database that isn't relational. Still, the comparison is useful as a starting point.
| SQL (relational) | NoSQL (most types) | |
|---|---|---|
| Data model | Tables with rows and fixed columns | Documents, key-value pairs, wide rows, graphs… |
| Schema | Defined up front, enforced by the DB | Flexible, often enforced by the app |
| Relations | Joins and foreign keys | Embed related data or join in the app |
| Transactions | ACID across many tables | Usually per item or document (some offer more) |
| Scaling | Vertical + read replicas; sharding is hard | Designed to scale horizontally |
| Queries | Any question with SQL | Fast for the access patterns you designed for |
Redis: the Swiss army knife
Redis is an in-memory key-value store with rich data types (strings, hashes, lists, sets, sorted sets, streams). Because it lives in RAM it answers in well under a millisecond.
- Caching query results and sessions
- Rate limiting with counters and TTLs
- Leaderboards with sorted sets
- Pub/sub and lightweight queues
- Distributed locks
It's rarely the source of truth: memory is limited and expensive, so the main data usually lives in another database and Redis holds the hot part.
Graph databases
In a graph database relationships are first-class: "Ana follows Bob, Bob liked this video". Questions like "videos liked by people I follow" or "how is this account connected to known fraudsters?" are a few hops instead of chains of expensive joins.
Great for social graphs, recommendations, fraud detection and knowledge graphs. Not great as a general store for everything else.
Real systems use several (polyglot persistence)
| Part of a YouTube-like app | Good fit |
|---|---|
| Users, channels, subscriptions, billing | Relational (PostgreSQL / MySQL) |
| Video files and thumbnails | Object storage (S3) + CDN, not a database |
| Comments and watch history at huge scale | Wide-column (Cassandra / Bigtable) |
| Sessions, hot counters, rate limits | Key-value (Redis) |
| Video search | Search engine (Elasticsearch / OpenSearch) |
| Recommendations "people like you watched" | Graph or precomputed tables |
| Metrics and monitoring | Time-series (Prometheus / TimescaleDB) |
Each extra database is one more system to run, back up and keep in sync, so add them only when the main database is clearly the wrong tool.
Key takeaways
- 01Relational databases give joins, constraints and ACID transactions; they're the default choice.
- 02NoSQL types trade flexible queries for scale or speed on specific access patterns.
- 03Redis is an in-memory key-value store: perfect for caches, sessions, counters and rankings.
- 04Graph databases shine when the relationships themselves are what you query.
- 05Big systems combine several databases, each for the job it does best.
Check your understanding
1 of 3
How should you choose a database type?
Related concepts
Sharding
Sharding splits one big database into several independent databases (shards), each holding a slice of the rows, so storage and writes scale with the number of machines.
8 min read →Caching
A cache stores copies of data that are expensive to get (slow query, far away server) so the next request can be answered from somewhere fast and close.
9 min read →Read-heavy vs write-heavy
A read-heavy part is read far more than it changes (a video page); a write-heavy part receives a constant flood of new data (view counts, analytics). Each one needs different tools.
7 min read →