← Lessons

quiz vs the machine

Silver1090

Databases

Key Value Store Access Patterns

Key value stores trade query power for speed, supporting little more than get and put by an exact key.

4 min read · intro · beat Silver to climb

The Simplest Model

A key value store is the most basic database shape. You store an opaque value under a unique key and later fetch it back by that exact key. The store treats the value as a blob and does not look inside it.

What You Can and Cannot Do

  • Get returns the value for a key, and put stores or replaces it.
  • Lookups by key are extremely fast, often a single hash lookup.
  • You generally cannot query by the contents of the value, only by the key.

Common Use Cases

  • Caching computed results or session data keyed by an id.
  • Feature flags and configuration looked up by name.
  • User sessions keyed by a session token.

Designing the Key

Because the key is the only way in, the key must encode everything you need to find the value. Teams build composite keys like user 42 cart, packing the access pattern into the key itself. If you need a second way to find the same data, you usually store it again under a second key.

Key idea

A key value store offers only fast get and put by exact key, so the key must carry the access pattern and the value stays opaque.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the main limitation of a key value store?

2. Why do teams build composite keys like user 42 cart?