Skip to content
mentoor

Topic 1 of 5 · 4 min read

Starting a database choice from access patterns

Goal: Turn a feature brief into an access-pattern list and pick a store that serves each pattern.

Choose a datastore by writing down how the data will be read and written, then match each pattern to a store. Do not start from a product name. "We need MongoDB" or "we need a vector database" is an answer. The question comes first.

Check yourself · 1 of 3

A team picks a database before any design. What should they write down first?

Choose one answer

Why it matters

Every store is fast at some questions and slow at others. A relational database answers "all orders for this customer in March" well. A key-value store answers "the session for this token" in one hop but cannot answer the March question at all. If you pick the store first, you find the mismatch in production. AI assistants make this worse: ask "what database should I use?" and you get a confident list of popular names with no knowledge of your reads.

How to do it

For each feature, write one row per access pattern:

  1. The operation: a read or a write, in one sentence ("show the 20 latest messages in a channel").
  2. How often, and how fast it must be. Use your own estimate, such as "100 per second at peak, under 200 ms".
  3. The shape of the key: by id, by range, by text search, by similarity, by aggregate over many rows.
  4. Consistency: must a user see their own write at once? Can a count be a minute old?
  5. Volume and growth: rows now, rows in two years, size per row.

Then look down the table. If most rows are "by id or small range, needs transactions, joins between a few entities", one PostgreSQL covers it. PostgreSQL also offers JSON columns, full-text search and extensions for vectors, so a second system must justify itself with a pattern the first cannot serve well, not with a feeling.

Before and after

Weak brief: "A chat app with search and recommendations. Suggest a stack." An assistant may answer: PostgreSQL, Redis, Elasticsearch, a vector database and Kafka.

Fixed: write the table first.

Pattern Rate Key Consistency
Post a message 50/s channel id read-your-write
Last 20 messages 300/s channel id, time read-your-write
Search messages 2/s free text a few seconds stale is fine
Similar channels 1/min embedding stale is fine

Three of four rows fit PostgreSQL with an index and its built-in text search. The fourth does not yet justify a new system at this scale.

What goes wrong

  • Resume-driven stacks. Five databases for a team of three, each with its own backups, upgrades and failure modes.
  • Ignoring writes. The table lists only reads, then the write rate breaks the choice.
  • Missing consistency. Nobody asked whether a stale read is acceptable, so it is decided by accident.
  • Planning for scale you do not have. Design for the next order of magnitude, not the one after that.

Examples

Brief to table

Brief: "Customers book a 30-minute slot with a coach and get a reminder." Patterns: book a slot (write, must not double-book, needs a transaction), list free slots for a coach and day (read by range), send reminders (scan by time, once a minute). All three are relational with a unique constraint on coach and time. One PostgreSQL, no queue database needed yet.

A pattern that does not fit

A feature adds "show 'related articles' by meaning". The access pattern is nearest-neighbour by embedding, a different key shape from anything else in the app. First try a vector extension in the existing PostgreSQL. Move to a dedicated vector store only if measured latency or volume demands it.

Key points

  • Write the access patterns first: operation, rate, key shape, consistency and volume.
  • Match each pattern to what a store is good at, then count how many systems you really need.
  • One PostgreSQL with indexes, JSON, full-text search and extensions covers many apps; a second store needs a pattern the first serves badly.
  • Every extra database adds backups, upgrades, monitoring and a new way to fail.
  • Ask an assistant to fill your access-pattern table, not to name a stack.

Common mistakes

  • Naming a product before listing reads and writes.
  • Listing reads only and forgetting the write rate and the transactions.
  • Adding a store for each feature by default instead of asking whether the current one can serve it.
  • Leaving consistency unstated, so a stale read becomes a bug report later.

Check yourself · 2 of 3

A feature needs lookups by id, a few joins and multi-row transactions. A teammate proposes adding a second database. What is the best response?

Choose one answer

Check yourself · 3 of 3

Which line belongs in an access-pattern table for a store decision?

Choose one answer

Practice items, not counted towards your mastery.

Start here