CLOUD CONCEPT

Key-Value Data Model

The key-value data model stores each value under a unique key so applications can retrieve, update, or delete it directly.

Cloud Concepts Hub →

What is Key-Value Data Model

A key-value model organizes data as associations between identifiers and values rather than primarily as related tables. It is useful for access patterns such as retrieving a session, shopping cart, or user preference by identifier, and it underpins many cloud NoSQL databases and caches.

The key-value data model associates a unique key with a value within a defined collection or namespace. The key identifies the record, while the value contains the application data. For example, the key cart:customer-482 might identify a shopping cart whose value contains product identifiers, quantities, and an update timestamp. The basic operations are reading, writing, and deleting data by key. The complete key must distinguish one record from another, even when it consists of multiple components.

Values can be simple strings, binary data, or structured objects, depending on the database. A basic key-value store may treat the value as opaque content that only the application interprets. More capable implementations can inspect attributes, update individual fields, or maintain indexes. Consequently, key-value does not mean that every record must contain only two scalar fields, and it does not prohibit storing a JSON-like object as the value.

Cloud applications use this model when they know how records will be requested. A web application can retrieve session data using a session token, while a device platform can retrieve the latest device state using a device identifier. Managed cloud services can distribute records across partitions using their keys and handle infrastructure tasks such as replication and capacity management. Good key design distributes requests as well as stored data; one extremely popular key can still create a hot spot.

The main trade-off is between efficient, predictable access patterns and flexible querying. Retrieving a known key is a natural operation. Finding every cart containing a particular product may require a secondary index, an additional lookup structure, or an expensive scan. Engineers should identify required queries before designing keys and indexes. Duplicating selected data across records can make reads simpler, but it also introduces additional writes and consistency responsibilities.

The model does not determine durability, consistency, or transaction support. Some implementations primarily serve as caches, where entries can expire or be evicted. Others are durable databases suitable for authoritative application data. Some offer strongly consistent reads, conditional writes, and transactions, while others expose different guarantees. For example, concurrent cart updates may require a conditional write or atomic operation to avoid one request overwriting another. These capabilities must be evaluated separately from the data model.

For AWS Certified Cloud Practitioner questions, recognize Amazon DynamoDB as a managed NoSQL database supporting key-value and document data models. It is distinct from relational database services such as Amazon RDS, which organize data into tables with relational querying capabilities. DynamoDB uses a partition key and can optionally use a sort key; together, those attributes identify an item when a composite primary key is configured. Do not assume that all NoSQL databases are key-value stores: document, graph, and wide-column models are also part of the broader NoSQL category.

Key aspects of Key-Value Data Model

Key-value modeling combines unique record identifiers and direct access with deliberate key design, while leaving query capabilities and operational guarantees to the implementation.

Unique key-based identity

Each record is identified by a unique key within its collection or namespace. Keys may be single identifiers or composite identifiers, so applications must supply the components required to identify the intended record.

Direct access by identifier

The model is well suited to reading or changing a record when its key is already known. Sessions, shopping carts, and device state are practical examples of this access pattern.

Implementation-dependent value structure

Values may be opaque bytes or structured data with addressable attributes. Check the database's supported types and update operations rather than assuming every implementation handles values identically.

Access-pattern-driven design

Design keys and indexes around the queries the application must perform. Queries that do not align with those structures may require scans, additional indexes, or duplicated records.

Partitioning and workload distribution

Distributed implementations can use keys to place data across partitions. Distribute traffic across keys where possible, because a frequently accessed record can become a bottleneck even when overall storage is well distributed.

Separate operational guarantees

Persistence, expiration, eviction, consistency, and transactions are properties of the chosen implementation, not guarantees of the model. Distinguish an authoritative database from a cache before deciding where application state belongs.

Cloud services for Key-Value Data Model

These services apply key-based access to different storage roles. DynamoDB can hold durable application records, while ElastiCache can cache frequently requested records to reduce repeated database reads. A cache-aside application checks ElastiCache first, reads DynamoDB on a miss, and then caches the result; it must also manage expiration and stale entries. MemoryDB offers a durable in-memory database option when its supported data structures and access patterns fit the workload. These services are alternatives or complementary components, not a required stack, and their consistency, persistence, and cost characteristics should guide selection.

Amazon DynamoDB image Amazon DynamoDB

Amazon DynamoDB is a managed NoSQL database supporting key-value and document data models. Items are identified by a partition key or a composite partition-and-sort key, and secondary indexes support additional access patterns.

Open Amazon DynamoDB →
Amazon ElastiCache image Amazon ElastiCache

Amazon ElastiCache provides managed in-memory caching with engines including Valkey, Redis OSS, and Memcached. Applications use keyed entries for cached database results, sessions, and other frequently accessed data, with behavior such as expiration and eviction depending on the engine and configuration.

Open Amazon ElastiCache →