Choosing between a key-value and a document database comes down to one question: does the database need to understand what is inside the value? If every read and write goes through one known key and the value can stay an opaque blob, a key-value store is the simpler and more predictable choice. If the application has to filter on fields inside the value, index them, or change one field without rewriting the rest, a document store is worth its extra machinery. In AI infrastructure and production SaaS systems, session state and short-lived request embeddings suit key-value, while embeddings metadata needs filtering on its fields. This is one of the data-layer decisions that sits under our broader AI in cloud overview.
Key-Value vs Document Database: Which One for an AI Workload?
For simple needs, the difference between the two is small. The Wikipedia entry on document-oriented databases says that for users who do not need advanced query, retrieval or update features, the distinction between the two “may be minimal”. The difference becomes expensive when the data model does not match the access pattern.
The divide is easy to state. Key-value stores treat stored values as opaque data, while document databases are built to interpret and query the internal structure of documents. So the practical test is a list of the reads and writes your application will actually make: if none of them reaches inside the value, the document store’s structure-awareness is cost you do not need, and if several do, a key-value store forces that work into your application code.
ScyllaDB argued in a May 2026 post that “key-value” is one of the most overloaded labels in the industry, covering both systems that map a string to an opaque blob and systems that map composite keys to typed, individually addressable columns, and that models should be compared by the depth at which you can address, read and write data. ScyllaDB is a database vendor with a stake in that framing, but the access-depth test is the useful part, and it holds up whichever products you are looking at.
What Is a Key-Value Database, and What Access Patterns Is It Actually Good At?
A key-value database stores values under unique keys and retrieves them by key, treating the value as opaque. The Dynamo paper (Amazon, SOSP 2007) describes the model plainly: simple reads and writes to a data item identified by a key, state stored as binary blobs, and no operations that span multiple data items. Dynamo exposes two operations, get() and put(), and treats both the key and the stored object as an opaque array of bytes. A 2013 NoSQL survey on arXiv adds the matching limitation: searches can usually be run only against keys, not values, and only as exact matches.
That narrow interface is the strength. Amazon built Dynamo for services that only needed primary-key access, including shopping carts, customer preferences, session management and product catalogues, because a relational database would have limited their scale and availability. A 2019 qualitative study of big-data storage lists similar uses: user profiles, session information, shopping cart data and product details. Zilliz, a vector database vendor, describes key-value architectures as built on hash-based indexing that gives O(1) key lookups regardless of dataset size.
The same 2019 study is just as clear about where key-value stops fitting: when a specific data value has to be queried, when several unique keys must be worked on together, when part of the value is updated often, or when values have relationships the application needs to use.
The label also hides variation between products. Redis, the usual example of a pure key-value store, offers hashes for field-level access to a session without deserialising the whole blob, plus secondary indexing through Redis Search for queries by field value. Once you rely on those, you are using document-like capability inside a key-value product, which is fine as long as the choice is deliberate. For where key-value sits next to wide-column, graph and search engines, our piece on NoSQL databases for big data covers the wider family.
When Do Secondary Indexes and Partial Updates Justify a Document Database?
A document database stores each record as a semi-structured document (such as JSON or BSON) and lets you query and update its fields. Wikipedia describes document stores as an extension of the key-value model that uses the internal structure of documents, and notes that documents in one collection may carry different fields. On top of key-based access, document databases typically offer a query language that returns documents by their content, such as every document where a given field matches a value. They also support updates that change individual fields rather than replacing the whole document.
Partial updates are one place the cost difference shows up. MongoDB’s $set operator modifies only the specified fields, which its manual says avoids unnecessary writes when you work with large documents, and a dotted path creates nested documents as needed. Without field-level updates, changing one entry means reading the whole value, deserialising it, applying the change, serialising it again and writing it all back. ScyllaDB’s analysis says the latency of that read-modify-write cycle grows with the size of the collection being updated.
Secondary indexes carry their own price. The MongoDB manual says each index on a collection adds overhead to writes, because every insert or delete adds or removes keys in each index, and an update touches whichever indexes cover the changed keys. Every index you add to support a read pattern adds cost on the write path.
So the extra cost is worth paying under specific conditions. A document store is worth choosing when reads filter on fields other than the key, when updates touch a small part of large values, or when record shapes vary within one collection. If none of those applies, the indexes and the query engine add write overhead and operational surface for no benefit.
How Do Key-Value and Document Databases Differ on Query Capability, Indexing, Consistency and Scaling?
Set side by side as their canonical designs describe them, the two models differ on five dimensions. Individual products blur the lines, so check the specific engine against each row.
| Dimension | Key-value store | Document store |
|---|---|---|
| Query capability | get and put by key; searches only on keys, as exact matches | queries on document content and metadata, such as field-value matches |
| Indexing | key lookups; secondary indexes only where the product adds them (DynamoDB GSIs, Redis Search) | most offer secondary indexes, and each one adds write overhead |
| Updates | whole-value replacement; read-modify-write for partial changes | field-level updates such as MongoDB $set |
| Consistency | Dynamo-style designs tune consistency through N, R and W quorums; distributed key-value stores generally forgo multi-key transactions | MongoDB offers single-document atomicity and, in later versions, multi-document ACID transactions |
| Scaling | simple scale-out, with keys partitioned by consistent hashing | MongoDB scales horizontally through sharding, with replica sets for failover |
The consistency row needs more than a cell. Gene Pang’s 2015 Berkeley thesis describes distributed key-value stores as giving up complex queries and transactions, offering access only to a single key or a contiguous key range, for scalability and performance. If an AI pipeline needs two records to change together (a model version and its rollout flag, for example), a pure key-value store leaves that coordination to your application, while MongoDB can put both in one document or, in later versions, one multi-document transaction. How replicas propagate writes is a separate question, covered in our comparison of asynchronous vs synchronous replication for AI data serving.
DynamoDB shows how far a product can stretch the key-value label. AWS’s Amplify documentation calls DynamoDB “a key-value and document database” and says its queries efficiently use at most two attributes: a hash key with strict equality and a sort key supporting range operations. The DynamoDB developer guide also describes global secondary indexes with partition and sort keys composed of up to four attributes each. The trade-offs matter more than the limits:
- Global secondary indexes update asynchronously, using an eventually consistent model.
- Strongly consistent reads are supported only on tables and local secondary indexes, never on a GSI or a stream.
- Index updates consume write capacity from the index itself, but updating an attribute that is neither an index key nor projected costs the index nothing.
- Projection types (KEYS_ONLY, INCLUDE, ALL) trade storage cost against query flexibility, and AWS says projecting most attributes can increase or even double storage cost.
Which AI Workloads Suit a Key-Value Store, and Which Suit a Document Store?
Each workload below is placed by how it is read and written, not by the kind of data it holds.
| Workload | Typical access | Better fit |
|---|---|---|
| Session state | read and write by session ID, expire when idle | key-value |
| Online feature cache | fetch features by entity key at inference time | key-value |
| Short-lived request embeddings | store per request, read back within minutes | key-value |
| Embeddings metadata | filter on metadata fields alongside vector search | document |
| Inference request logs | query by field; fields change across releases | document |
Session state. Redis’s documentation recommends a session store for sharing per-user state (login context, carts, preferences) across stateless application servers, with one hash per session ID and a key expiry that removes inactive sessions without any external job. Redis says moving session reads to a relational database instead adds 5 to 20 ms per request.
Feature caches. Online feature serving is a keyed lookup by entity at inference time, and an industry overview from Introl lists Redis, DynamoDB and Cassandra as the key-value stores used for it. The wider design of the online and offline stores is covered in our guide to data infrastructure for ML.
Short-lived embeddings. A Towards Data Science article describes storing every embedding for a user request in Redis under the request’s unique ID, a lightweight design suited to short-lived, low-query contexts.
Embeddings metadata and inference logs. MongoDB Vector Search lets you pre-filter embeddings on boolean, date, objectId, numeric, string and UUID fields. Inference logs change shape as models and prompts change, which suits a schema where documents in one collection can carry different fields. Logs fit a key-value store only if access stays put blob, get blob on ephemeral data with simple lookups. As soon as someone asks “show me every failed call to model version X last week”, the blob design breaks down.
When Does Vector Search Outgrow a Key-Value or Document Store?
Vector search is a different need from both key lookups and field matches. It is approximate nearest-neighbour search over high-dimensional embeddings, built on index types such as HNSW, IVF or PQ, rather than a key lookup or a field match. Whether that needs its own system depends on scale and query volume.
The Towards Data Science author found that for their ephemeral use case a vector index needed 11,510 queries before the time saved per query paid back the time spent building it, so a key-value store won. The same author says millions of embeddings with high query load across a shared corpus favour a vector database. Document stores sit in between: MongoDB Vector Search runs a separate vector index on embeddings of up to 8192 dimensions alongside normal collection data, and Zilliz suggests key-value stores with vector extensions when vector needs are modest in collection size and dimensionality. Choosing among dedicated engines is a separate question, covered in our vector database comparison.
What Does Picking the Wrong Data Model Cost?
The 2019 big-data storage study calls the data model one of the biggest NoSQL challenges and says an inappropriate model can significantly affect system performance.
Discord’s account of its message store is a useful real case. The company started with everything in a single MongoDB replica set, chosen deliberately for fast iteration and planned from the start for easy migration. When it had to move, it first studied its traffic and found reads were extremely random with a read/write ratio of about 50/50. One explicit requirement was “not a blob store”, because writing thousands of messages per second would not work if blobs had to be deserialised and appended to constantly. It chose Cassandra, which Discord describes as a KKV store with a partition key and a clustering key.
Moving data between providers adds hard costs on top of engineering time. Kreante’s vendor lock-in guide cites list egress prices of $0.08 to $0.09 per GB, which puts a one-petabyte migration at roughly $80,000 to $90,000 before engineering time, parallel running or application rework, and names managed databases as where lock-in hits hardest. How the data layer shapes reliability more broadly is covered in big data DB choices for production AI.
How to Avoid Locking Yourself In
The defence is to do the access-pattern work first. AWS’s DynamoDB guidance says not to design the schema until you know the questions it needs to answer, and for existing applications to analyse query logs to find the real access patterns. ScyllaDB gives the same order of operations: start with the access patterns, let the data model follow, then pick the technology.
Before committing, we would check three things on a representative slice of traffic:
- Bytes read per request against bytes used. A large gap means you are fetching whole values to read one field.
- Application-side filters. Count the filters your code runs that the database could have run; a document store can run field-value queries itself.
- Update latency as collections grow. Watch whether it stays flat or climbs with each read-modify-write.
Keeping database calls behind a thin data-access layer will not make a migration free, but it limits the rewrite to one place.
The risk is a workload that starts opaque and stops being opaque, such as a session blob that later needs a “find all sessions for tenant X” query. Treat that future query as part of the decision now.
FAQ
Is MongoDB a Document Database or Key-Value?
MongoDB is a document database that stores data as BSON documents. Every document has a key, but you can also query, index and update fields inside it, which a plain key-value store cannot do.
Is Apache Cassandra a Key-Value Database?
A NoSQL survey places Cassandra among wide-column stores, with Dynamo-inspired key-value DNA. Discord describes it as a KKV store, where a partition key and a clustering key together form the primary key.
Is Redis a SQL or NoSQL?
Redis is a NoSQL key-value database, and ScyllaDB calls it the canonical example of the opaque key-value model used for caches and session stores.
What Is an Example of a Key-Value Database?
Redis, DynamoDB and etcd are common examples.