Skip to content
Part IA Michaelmas Term

Key-Value Stores

The associative store, generalised

A key-value store generalises the associative array (dictionary) from Lecture 1: values are blobs (arbitrary sequences of bytes), not just strings. Any structure inside the blob is opaque to the key-value store — it is the application’s concern, not the DBMS’s.

Store:   key ──→ blob
         string   bytes (opaque)

Opaqueness implies the DBMS knows nothing about what is stored. It would not mind if values were encrypted and it never saw the encryption keys. This is both a strength (simplicity, security) and a limitation (no querying within values, no secondary indices without application effort).

Distribution

Many key-value store implementations are distributed: data is spread over all participating machines as shards. The typical mechanism:

  1. Hash the key to produce a shard identifier.
  2. Route the read/write to the machine responsible for that shard.

This provides:

BenefitMechanism
Load balancingHash distributes keys uniformly across shards
RedundancyEach shard may be replicated across multiple machines for durability
ScalabilityAdding machines increases total capacity; rebalancing redistributes shards

ACID vs. BASE semantics

Implementations can range between full ACID guarantees and relaxed BASE semantics:

PropertyACID (traditional RDBMS)BASE (many K/V stores)
AtomicityFull rollback on failureBest-effort; partial writes possible
ConsistencyInvariants enforced by DBMSApplication-level, eventual
IsolationSerializable transactionsOften none or read-committed
DurabilityWrite-ahead log, fsyncReplication to N nodes; quorum writes

A note on redundancy

It is important to distinguish two kinds of redundancy:

KindMeaning
Physical redundancyMultiple copies of the same data for durability (replication across machines)
Schema redundancyThe same data stored in multiple places within the logical model (denormalisation)

Key-value stores provide physical redundancy through replication. Schema redundancy is an application-level choice — the store itself cannot help with or prevent denormalisation, since the blob contents are opaque.

Use cases

  • Caching (e.g., Redis, Memcached): fast in-memory lookups with optional persistence.
  • Session stores: web session data keyed by session ID.
  • Configuration stores: distributed configuration that must be available across a fleet.
  • Shopping carts: per-user carts that tolerate eventual consistency.

Summary

  • A key-value store maps string keys to opaque blobs.
  • Distribution provides load balancing, redundancy, and scalability via hashed sharding.
  • ACID vs. BASE is a spectrum; different stores choose different points.
  • Physical redundancy (replication) is distinct from schema redundancy (denormalisation).