Data · L1Choosing a database

Choosing a database

Pick a database from how you read and write your data, not from what is popular. Then count what it costs to run.

L1 Must-knowData18 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 22 Oct 2026 · How we check content
Section 1 of 8

What broke

Discord built the first version of its app in early 2015. Every chat message lived in one MongoDB replica set. This was on purpose, and the team planned a path to move later. 1

Around November 2015, they had 100 million stored messages. Then the data and the index no longer fit in RAM. Latency became unpredictable. 1

Before they picked a new database, they studied how the app really used messages. Reads were very random, and reads and writes were about 50/50. They also wrote down what they needed: linear scaling, automatic failover, low maintenance, predictable speed, a proven product, and open source. 1

Cassandra was the only database that met all of these needs. It also came with a trade-off. It gives up strong consistency to stay available. Discord wanted that, and accepted eventual consistency. 1

In 2017 the cluster had 12 Cassandra nodes. By early 2022 it had 177. Hot partitions, compaction backlogs and garbage collection pauses caused latency spikes. 2

In May 2022, Discord moved to 72 nodes of ScyllaDB, a Cassandra-compatible database. The p99 latency to read old messages fell from 40–125 ms to 15 ms. 2

So a choice is not "right forever". It fits a set of access patterns at one size. In this lesson you will learn to ask the questions Discord asked, before your data outgrows your database.

Section 2 of 8

The idea in simple words

There is no best database. There are databases that fit some ways of reading and writing data, and fit others badly.

So start from your access patterns: which questions the app asks, how often, and how fast the answer must be. Then add your requirements: transactions, consistency, size, and who will run it at 3 a.m.

The key idea. First list how you will read and write the data. Then pick the simplest database that serves those patterns, and that your team can run. Popularity is not a requirement.

DB-Engines sorts hundreds of systems by data model. Its main groups include relational, key-value, document, wide column, search engines, time series, graph and vector. Some systems belong to more than one group. 4 The AWS decision guide uses a similar list. It adds in-memory as a group and has no search engine group. 3

Section 3 of 8

How it works

Step through the questions. Each "yes" points to a family. Use Next and Back, or the ← and → keys.

From questions about your data to a database familyRows that link together?orders, money · transactionsRelational Only get and put by key?sessions, carts · huge trafficKey-value Search words in text?typos, ranking by relevanceSearch Data points over time?metrics, sensors, pricesTime-series Paths across many links?friends of friends, fraud ringsGraph ✓ Not sure? Start with Postgresadd a new store only for a proven need SeniorPath
  1. Do your records point at each other, like orders, users and payments? Must several rows change together or not at all? Then start with a relational database such as Postgres or MySQL.
  2. Do you only ever read and write one item by its key, at very high traffic? A key-value store such as DynamoDB or Redis fits. A document store like MongoDB fits when one key holds a nested JSON-like record.
  3. Do users type words and expect ranked results, even with small typos? Add a search engine such as Elasticsearch, usually as a copy of data that lives in your main database.
  4. Is most of the data timestamped points, like CPU use every 10 seconds? A time-series store such as TimescaleDB or InfluxDB keeps it cheap to write, keep and query by time range.
  5. Is the question about paths, like friends of friends or money moving through many accounts? A graph database such as Neo4j stores the links themselves, so it can follow many hops.
  6. No clear yes? Start with one relational database. It covers most needs for a long time. Add another store only when a measured need shows up, and count its running cost.
Step 1 of 6

The main families, as their own docs describe them

  • Relational (Postgres, MySQL). Tables, joins, constraints and ACID transactions. Postgres also stores JSON and supports every SQL isolation level. 5
  • Key-value (DynamoDB, Redis). Get and put by key. AWS suggests it for session stores and shopping carts. 3 DynamoDB is fully managed and also has ACID transactions across tables. 9 Redis keeps data in memory. 10
  • Document (MongoDB). JSON-like documents with nested fields, in collections without a fixed schema. 6
  • Wide-column (Cassandra). Tables split into partitions across many nodes, with eventual consistency. 8
  • Search engine (Elasticsearch). Built on Apache Lucene, it stores JSON documents in indices for search and analytics. 12
  • Time-series (TimescaleDB, InfluxDB). TimescaleDB splits Postgres tables into chunks by time. 15 InfluxDB is built for event and time-series data, like server and sensor monitoring. 16
  • Graph (Neo4j). Nodes and relationships. The links are stored with the data, so queries follow them without joins. 14
  • Vector (pgvector). Finds the nearest vectors, for example similar texts. pgvector does this inside Postgres, next to your other data. 17

What each one is bad at

Each family pays for its strength somewhere.

Cassandra chose not to support transactions across partitions, distributed joins or foreign keys. Fast queries must give the partition key. 8 So you design one table per query, and changing the questions later is hard.

MongoDB has multi-document transactions. Its docs warn that a distributed transaction costs more than a single-document write, and that it does not replace a good schema. 7

Redis keeps data in memory (Redis in depth goes further). If you turn on its append-only file, the default policy syncs to disk once per second. A crash can then lose about 1 second of writes. With snapshots only, you can lose minutes. 11 That may be fine for a cache, but usually not for money.

Elasticsearch makes a new document searchable within about 1 second, not at once. 13 So keep the real data in your main database, and copy it into the search index.

Transactions and consistency

Ask: must several records change together, or not at all? Money, stock and bookings usually need this. Relational databases are built for it: Postgres has been ACID-compliant since 2001. 5 If you pick a store with weaker transactions, your app code must handle the gaps. The transactions lesson and the CAP lesson explain what you give up.

Scale

Write numbers, not adjectives. How many rows in two years? How many reads and writes per second at peak?

Kailash Nadh, the CTO of the Indian trading platform Zerodha, makes this point. A Postgres node with a replica, good partitions and indexes can hold hundreds of billions of records and terabytes of data. 18 He argues that you often do not need a distributed database. 18 This lesson agrees: most apps fit one Postgres for a long time. When they do not, replication and sharding come next.

Running cost and team skills

Someone must back it up, upgrade it, watch it and fix it at night. If you host it yourself, your team does the maintenance, monitoring and patching. A managed service takes most of that work. 3 It usually costs more per hour, so compare that with the engineer time it saves.

Skills matter too. AWS suggests that a team already running Postgres should first try pgvector before a new vector store. 3 Dan McKinley says a new technology brings more "unknown unknowns". He suggests a young company gets only a few "innovation tokens", maybe three, to spend on new tools. 19

Polyglot persistence

Using several stores in one system is called polyglot persistence. AWS gives a shop example: a document store for the catalogue, DynamoDB for fast browsing, and Aurora for orders and stock. 3

Martin Fowler wrote about it in 2011. He warns that it costs complexity. Each new store is a new interface to learn and to tune. 20 You also have to keep the copies in sync.

Section 4 of 8

Trade-offs

The table sums up the sources above. The "Bad at" column is partly this lesson's own advice, so test it against your own case.

FamilyGood atBad atTypical use
RelationalJoins, constraints, ACID transactions, new queries later.Writes beyond one big node need sharding.Users, orders, payments. Most apps.
Key-valueVery fast get and put by key at huge scale.Queries not by key need extra indexes. No joins.Sessions, carts, cache.
DocumentNested records that match your code.Data with many links between records. Multi-document transactions cost more.Catalogues, profiles.
Wide-columnHeavy writes spread over many nodes.Joins, cross-partition transactions, new query shapes.Messages, events at very large scale.
Search engineRanked full-text search, typos, filters.Being the main copy of the data. New data is not searchable at once.Product and log search.
Time-seriesCheap writes and time-range queries.Data that is not mostly timestamped points.Metrics, sensors, prices.
GraphFollowing many hops of links.Simple lookups any database can do. One more system to run.Fraud rings, recommendations.
Vector"Find similar" by embedding.Being the only store. You still need the source data.Semantic search, RAG.
Section 5 of 8

At work: how a senior uses this

  • Write the access patterns first: the top 10 queries, read/write ratio, peak rate, and data size in two years.
  • Mark which data needs transactions. Money and stock usually do.
  • Start with the database the team already runs well. Ask "what can't it do?" and prove it with a test.
  • Prefer a feature of the current database (JSON column, pgvector, TimescaleDB) before a new system.
  • For each new store, name the owner, the backup plan, the on-call runbook and the monthly cost.
  • Choose managed unless you have a clear reason and the people to self-host.
  • Plan how data gets into a second store, for example with change data capture, and how you rebuild it.
  • Write the decision down in a short record with the patterns, options, and the reason.

Checklist before you pick:

  1. Access patterns listed?
  2. Transactions needed where?
  3. Size and rate in two years, as numbers?
  4. Can the current database do it?
  5. Who runs it, and is it managed?
  6. How do you leave it later?
Section 6 of 8

With AI

What to ask the agent

"Here are our 10 most common queries, our read/write ratio and our data size. For each database family, say which queries it serves well and which it serves badly. Do not recommend a product until the end."

"We run Postgres. We need vector search for 2 million documents. Compare pgvector with a separate vector store, including backups, sync and on-call work."

"List the operational tasks our team takes on if we self-host Cassandra instead of using a managed service. Link each task to the official docs."

What to check yourself

  • The agent's family descriptions match the official docs, not a blog post or its memory.
  • Every claim like "scales to millions" names a source or comes from your own load test.
  • The comparison includes running cost: backups, upgrades, monitoring and on-call.
  • The answer says how data stays in sync between stores.
  • The agent did not pick the newest tool just because it is new.
Section 7 of 8

Check yourself

1. You are starting a new shop app with users, orders and payments. Nobody has measured any load yet. What is the safest first choice?

Show answer

One relational database such as Postgres. Orders and payments link to each other and need transactions. A relational database handles both, and you can add a store later for a proven need.

2. What made Discord leave its single MongoDB replica set?

Show answer

Around 100 million messages, the data and index no longer fit in RAM, and latency became unpredictable. Discord's 2017 post says exactly this, around November 2015.

3. In Cassandra, which query is fast?

Show answer

One that gives the partition key. The Cassandra docs say all performant queries supply the partition key. Cross-partition transactions and distributed joins are not supported.

4. Your Postgres app needs "find similar products" with vector embeddings. What should you check first?

Show answer

Whether the pgvector extension in your current Postgres is enough. AWS suggests teams that already run Postgres start by trying pgvector. It keeps vectors next to the rest of the data.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 20 sources and related lessons
  1. Stanislav Vishnevskiy, “How Discord Stores Billions of Messages”, Discord blog (2017) (opens in a new tab)
    Why one MongoDB replica set stopped fitting, the access patterns Discord measured, its list of requirements, and why it chose Cassandra.
  2. Discord Engineering, “How Discord Stores Trillions of Messages” (2023) (opens in a new tab)
    What the Cassandra choice cost five years later, and the move to 72 ScyllaDB nodes.
  3. AWS, “Choosing an AWS database service” (decision guide) (opens in a new tab)
    Database families with use cases, the criteria to compare, self-hosted versus managed, and a mix of databases for one shop.
  4. DB-Engines, “Ranking per database model category” (opens in a new tab)
    The list of database models that DB-Engines uses to classify hundreds of systems.
  5. PostgreSQL: About (opens in a new tab)
    What Postgres is, and its long feature list (JSON, constraints, all isolation levels, many index types).
  6. MongoDB Manual: What is MongoDB? (opens in a new tab)
    Documents, collections without a fixed schema, multi-document transactions, sharding.
  7. MongoDB Manual: Transactions (opens in a new tab)
    The warning that distributed transactions cost more than single-document writes and do not replace good schema design.
  8. Apache Cassandra documentation: Overview (opens in a new tab)
    Partitioned wide-column storage, queries that need the partition key, and what Cassandra does not support.
  9. Amazon DynamoDB Developer Guide: What is Amazon DynamoDB? (opens in a new tab)
    A fully managed NoSQL database, its use cases, and ACID transactions across tables.
  10. Redis docs: Get started with Redis Open Source (opens in a new tab)
    An in-memory data store used as a cache, document and vector database, streaming engine and message broker.
  11. Redis docs: Redis persistence (opens in a new tab)
    RDB snapshots and the append-only file, and how much data each can lose.
  12. Elastic docs: The Elasticsearch data store (opens in a new tab)
    A distributed search and analytics engine built on Apache Lucene that stores JSON documents in indices.
  13. Elastic docs: Near real-time search (opens in a new tab)
    A new document becomes searchable within about 1 second.
  14. Neo4j docs: What is a graph database (opens in a new tab)
    Nodes, relationships and properties, and why graph queries do not need joins.
  15. Tiger Data (TimescaleDB) docs: Understand hypertables (opens in a new tab)
    Postgres tables that are split into chunks by time automatically.
  16. InfluxDB 3 Core documentation (opens in a new tab)
    A database built for event and time-series data, with its common use cases.
  17. pgvector (GitHub README) (opens in a new tab)
    Vector similarity search inside Postgres, next to the rest of your data.
  18. Kailash Nadh, “Scaling with common sense”, Zerodha tech blog (opens in a new tab)
    Zerodha's CTO (2020) on why a relational database works, almost always.
  19. Dan McKinley, “Choose Boring Technology” (opens in a new tab)
    Innovation tokens, unknown unknowns, and the hidden running cost of each new database.
  20. Martin Fowler, “Polyglot Persistence” (2011) (opens in a new tab)
    The idea of several data stores per system, and its cost in complexity.

Case studies: Discord: Moving trillions of messages from Cassandra to ScyllaDB · Uber: Schemaless: an append-only datastore built on MySQL

Related: Data models and query languages · Data modelling for NoSQL · PostgreSQL in depth · B-tree vs LSM-tree · Transactions and isolation levels · Search systems and inverted indexes · Time-series and specialised stores (coming soon) · Vector databases and ANN search (coming soon)

Next: Data modelling for NoSQL shows how to design tables around access patterns. For how storage engines pay for writes, see B-tree vs LSM-tree. For search, see Search and inverted indexes.

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper