Skip to content

Choosing a datastore

Phase 3 · Data and state · 15 min read · 5 Atlas cases linked

What you'll be able to do

  • Turn a workload's reads, writes, latency, and growth into datastore requirements.
  • Choose a sensible home for transactional records, files, analytics, and retrieval data.
  • Explain what an approximate vector index gains and what it can miss.

Begin with the questions the product asks

A datastore is a way to answer particular questions while preserving data under particular failures. Before naming a product, write down the operations. For a document assistant: "create a user," "list this user's runs," "fetch checkpoint 17," and "find chunks similar to this query" are four different access patterns. Their records, query shapes, and correctness needs differ.

Ask Example requirement What it changes
Reads and query shape Look up one run by ID; filter runs by user and time Keys and indexes; whether joins or full-text search matter
Writes and updates Add 50 chunks per document; update run status Write rate, transactions, and contention
Size and growth 1 million chunks now; 10 million next year Index size, storage cost, and partitioning plans
Consistency A user must see a new run immediately Whether a delayed replica or index is acceptable
Latency and throughput Retrieval under 100 ms at 100 requests/s Which operations need a measured fast path
Retention and recovery Delete a user's data; restore after a mistake Backup, expiration, and deletion design

These numbers are requirements to measure, not promises made by a database label. A 100 ms retrieval budget includes the application, network, filtering, and ranking; the datastore gets only part of it. Start with the simplest store that satisfies the important operations, then test with realistic data and query distributions.

Match the operation to the family

Family Actually good at Boundary to notice
Relational (PostgreSQL, MySQL, SQLite) Structured records, joins, constraints, transactions Large blobs and broad analytical scans are awkward
Key-value (Redis, DynamoDB-style) Fetch or update by known key New query shapes may require extra indexes or copies
Document (JSON documents) Read or replace a flexible aggregate together Cross-document joins and constraints can become app code
Wide-column (Cassandra-style) Large write volume with queries designed around a partition key Ad hoc queries across partitions are difficult
Search engine Full-text queries through an inverted index Usually a derived index, not the only source of truth
Graph Repeated traversals across relationships A simple lookup or one join needs no graph engine
Time-series Timestamped measurements, retention, time-window aggregates General transactions and arbitrary joins may be weak
Columnar warehouse Aggregates over many rows and a few columns Small, frequent row updates are a poor fit
Object storage (S3-style) Durable, inexpensive blobs such as datasets and checkpoints Higher latency than local memory or indexed rows; updates usually replace whole objects
Cache Repeated answers with an acceptable freshness window Entries can expire or be evicted
Vector index/database Nearest-neighbor search over embeddings Similarity is approximate in many fast indexes

"NoSQL" groups several of these families; it does not specify one consistency model or one query language. A search engine's inverted index maps terms to documents containing them. BM25, a common full-text ranking method, scores how well a document's terms match a query, accounting for term frequency and document length. That answers a different question from vector similarity: exact names and error codes can matter even when embeddings look similar. Many retrieval systems combine both signals.

Separate transactions from analysis

An OLTP store serves operational requests: insert a run, read its status, update one row. Row-oriented storage keeps a record's fields together, which suits those requests. An OLAP store serves analysis: scan many runs and compute average latency by model and day. Column-oriented storage keeps values of the same field together, so a query reading model, day, and latency need not read every prompt or response field. Parquet-style files use this idea for analytical datasets.

Suppose a table has 10 million runs and 20 fields, while a report needs 3 fields. At the simplest field-count level, the report touches 3/20, or 15%, of the columns. Compression and indexes change real I/O, so 15% is an intuition, not a predicted speedup. Send reporting workloads to a warehouse or analytical files when they begin competing with operational traffic. That data is usually copied asynchronously, so a dashboard can lag behind the source.

Decide how fresh and available reads must be

Data copies introduce a choice. During a network partition, a replicated system cannot both guarantee that every read sees the latest successful write and answer every request on both sides. This is the practical CAP question: which requests may fail, and which may return older data? Outside partitions, PACELC asks about the everyday latency cost of coordinating copies for stronger consistency. Neither acronym chooses a database for you; write the user-visible behavior you need. See replication and consistency for the mechanics.

For example, an account permission change should take effect before a later authorized read. A search index that takes seconds to show a newly uploaded document may be acceptable if the UI says "indexing." Use a transaction for the authoritative change, then update the derived index and handle lag explicitly. If the index update fails, retry it from durable state. Adding stores buys specialized queries but also creates synchronization, consistency, monitoring, backup, and deletion work.

Assemble an AI product from a few stores

One product, several stores: each kind of data goes to the store built for how it is read.

Start with PostgreSQL for users, metadata, and runs when its transactions and indexes meet your workload. SQLite can serve local tools and some multi-process services when its limited write concurrency fits the workload; MySQL is another relational choice. Keep dataset and checkpoint bytes in object storage, with a versioned path such as models/run-42/step-1000/checkpoint.bin. Store the path and ownership in the relational database. Do not put large training datasets into a transactional table merely because they have a filename: bulk reads, storage cost, and backup size are different from row lookups.

For retrieval, save each chunk's source ID, owner or access scope, and document version alongside its embedding. Use that index metadata to narrow candidates, then check every candidate's current permission against the authoritative store before returning it, because the index copy can be stale. A revocation must take effect without waiting for index synchronization. If the permission check is unavailable, fail closed: return nothing unchecked. Fetch extra candidates if rejections could leave too few. A vector extension in PostgreSQL can be enough when the corpus and query rate are modest and keeping metadata, permissions, and vectors together simplifies updates. A dedicated vector system becomes worth evaluating when measured search latency, scale, or index operations exceed that design. Test filtered queries, not just an unfiltered nearest-neighbor demo.

Exact search compares a query with every eligible vector. For 1 million vectors, that is up to 1 million similarity calculations per query. Approximate indexes score fewer candidates, but may omit the true nearest neighbor.

One simple design uses random hyperplanes through the origin. Each hyperplane contributes one bit saying which side a vector falls on. The bit string is the vector's bucket signature, and the Hamming distance between two signatures counts the positions where they differ. Search the query's bucket first, then buckets with more differing bits until you have enough candidates. A true neighbor just across one hyperplane sits in another bucket; if the query's bucket already holds enough candidates, that neighbor is never scored.

Measure recall at k against exact results: if an approximate top 10 contains 8 of the exact top 10, recall@10 is 8/10 = 0.8. Also count comparisons and measure latency on representative queries. A cache can reuse repeated prompt results, but its entries need versioned keys and a durable source for anything that must survive eviction.

Plan for change and deletion

Schema changes exist even in a "schemaless" document store. If old documents lack owner_id while new code assumes it, you have a schema migration in code. Version records, make readers tolerate old shapes during migration, and backfill deliberately. Keep the authoritative schema and derived indexes clear so you know what to rebuild.

For each store, decide retention, backups, restore tests, access control for personal information, and who pays for bytes and requests as data grows. Deleting a user means finding their relational rows, objects, cached responses, search documents, and analytical copies; a single SQL delete is insufficient. Define a deletion workflow and verify completion. Backups may have their own retention schedule, which must be part of the policy.

For AI engineers

For AI engineers

Your training script often reads a directory of files and writes a checkpoint. In production, those files need stable versions, ownership, retention, and a recovery path. Object storage holds dataset and checkpoint bytes; a transactional database records which version a run used and whether it completed. A feature store is another application of this split: it serves named feature values to training or inference while tracking freshness and provenance. Its online read path and offline historical data can have different storage needs. The same discipline applies to embeddings: keep chunk metadata with the vectors, check current authorization before returning a chunk, test filtered retrieval, and compare approximate results with an exact baseline before buying a specialized service.

Common mistakes

  • Choosing by hype: start from actual queries and measured limits, not a product category's reputation.
  • Rebuilding joins in code: if every document read needs several related entities and constraints, a relational model may be simpler.
  • Forcing one store to do everything: use an object store for large files and an analytical store when scans harm transactions, but add each one for a concrete need.
  • Treating Redis as the only copy: plan persistence and recovery explicitly if it must hold durable data; otherwise use it as a cache.
  • Assuming approximate search is exact: track recall on filtered, representative queries.
  • Forgetting deletion: enumerate every copy, including caches, indexes, objects, and backups.

Check yourself

A run record must update atomically with its status, while a 4 GB checkpoint is read only by path. Where does each go?

Put run metadata and status in a relational database transaction. Put checkpoint bytes in object storage and store their versioned path in the run record.

A report scans millions of runs but uses only model, day, and latency. Why might columnar storage help?

It can read those columns without loading every field of each row. Copying data to an analytical store also keeps the scan from competing with operational requests, at the cost of possible lag.

A vector search returns the right topic but includes a document the user cannot access. What failed?

Authorization against current permissions failed. Index metadata may narrow candidates but can be stale, so check each candidate in the authoritative store before returning it, and fail closed if that check is unavailable. Similarity cannot grant permission.

An approximate search makes 100 comparisons instead of 10,000 and finds 7 of the exact top 10. What is recall@10, and what else should you measure?

Recall@10 is 7/10 = 0.7. Measure latency and recall on representative, filtered queries; decide whether missed neighbors are acceptable for the product.

Lab

First answer the short written exercise in the README: place three workloads in stores. Then build a tiny in-memory vector store in code/choosing-datastore/ using only Python. Implement cosine similarity, exact top-k search, and exact-match metadata filters. Add recall_at_k to compare approximate and exact results. Build a seeded random-hyperplane index and count similarity calculations per search. Compare its candidate count and recall with exact search on a fixed dataset. Run: cd code/choosing-datastore && PYTHONPATH=starter python -m pytest tests -q

Go deeper

See it in the wild

Open these real architectures and find the idea in the diagram. Predict how it is used before you read the analysis.