What Is a Key-Value Store? Design Keys and Expiration for Your Lookups
A key-value store is a data model that handles data as pairs: a unique key and its associated value. An application usually names a key to read, store, replace, or delete a value. This makes access by a known key straightforward, but products differ in how freely they can search values by several fields, so define the required access patterns first.
What do the key and value do?
The key is the name or identifier used to find a record; the value is the data associated with it. A value may be a string or binary blob, or, depending on the product, a more structured list, hash, or document. Redis strings are byte sequences, and Redis also provides data types such as lists and hashes. Amazon DynamoDB identifies table items by primary key and supports both key-value and document data models. The label “key-value store” alone therefore does not tell you the value's structure or query capabilities.
For example, imagine storing a login session under a key such as session:<sessionID>. A request retrieves the value by session ID, and logout or expiration removes the key. When the key represents a known read path, the design differs from a relational query that searches arbitrary combinations of customer email, status, and signup date.
SET session:abc123 {"userId":"u42","role":"member"} EX 1800
GET session:abc123This illustrative Redis example stores JSON text as a string and sets a 1,800-second expiration. It was not run or verified on a server. Expiration helps remove stale data after a session ends, but does not by itself guarantee durability or recovery.
How should you design key names and access patterns?
Write down the requests the application needs before inventing keys. session:<id> finds one session by its ID; cart:<userId> finds a user's cart. Combining a type and identifier, as in user:<id>:profile, makes keys easier to read and distinguish; separators also reduce naming collisions. Redis documentation recommends a consistent key schema and shows colons as a convention for dividing key sections. Redis does not enforce namespaces, so the application and team must follow the naming rules.
Amazon DynamoDB can model more than direct key lookup: a partition key and sort key can support range queries over a group of items. For example, PK=USER#42 and SK=ORDER#2026-11-22#1042 could group one user's orders and let a query bound the sort-key range. This is an illustrative key design; the actual table, indexes, and request volume need to shape it. DynamoDB Query requires a partition-key value and optionally adds a sort-key condition. That is different from a general search over arbitrary attributes.
| Access need | Key-value design direction | Check before choosing |
|---|---|---|
| Retrieve one value by a known ID | Put the ID in the key and read it directly | Key collisions and missing-key behavior |
| A value is no longer needed after some time | Set a TTL or expiration | Whether it is safe to disappear and whether separate recovery is needed |
| Read a user's items in time order | Use user identity as the partition key and time/type in the sort key | Hot partitions, item volume, and required ranges |
| Search arbitrary combinations of fields | Consider secondary indexes, search, or another data model | Extra index storage/write cost and consistency |
When does this approach fit, and where are its limits?
Sessions, cache entries, feature flags, and per-user carts can fit key-value access when the key is known and one item or a group is read frequently. For a cache, decide where the source of truth lives and how to refill the cache when it is empty or expires. For a user-dependent value such as a session, check whether expiration is sufficient or whether durability, replication, backup, and recovery need separate guarantees. Redis expiration removes a key after its configured time; it does not replace a service-wide backup policy.
If the main need is a search such as “users in Seoul with at least three unpaid orders last month,” a single key is not enough. Precomputing every combination as separate keys or indexes creates derived data to update and consistency between the source and indexes to maintain. Relational joins and constraints may make this clearer; if document, search, or analytics features matter, compare stores that actually support those operations.
Document the read and write requests, data size, expiration rules, consistency and durability needs, and recovery procedure together. Check that the chosen product supports not only direct key lookups but also the required range and conditional queries. Decide what users should experience after data expires or is deleted, and how recovery works. These decisions preserve the benefits of simple lookup without treating the store as a general-purpose query engine.
Sources and scope
[Redis: Keys and values](https://redis.io/docs/latest/develop/using-commands/keyspace/)
[Redis: SET command](https://redis.io/docs/latest/commands/set/)
[Redis data types](https://redis.io/docs/latest/develop/data-types/)
[Amazon DynamoDB core components](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html)
[Amazon DynamoDB Query](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html)
Redis and DynamoDB behaviors are based on official documentation checked on 2026-11-22. Their features are not generalized to every key-value store. The session and DynamoDB key examples are illustrative; no commands were executed and no performance was measured.