Free preview

What Is a Key-Value Store?

Why this matters: this chapter is the one place in the course where you design a real distributed system end to end. Every mechanism in it — consistent hashing, quorums, vector clocks, gossip — reappears inside other designs for the rest of your career.

Key takeaway

Key-value stores are distributed hash tables (DHTs). A unique key, generated by a hash function, binds to a specific value, and the store remains agnostic to the value's structure. Values can be blobs, images, server names, or any user-defined data.

What goes in it

Values should generally be small — kilobytes to megabytes. For large datasets, store the content in a blob store and keep only a link to it in the value field.

The store never inspects the value. That opacity is the source of both its simplicity and its speed: there is no schema to validate, no query to plan, and no index to maintain — just hash the key and fetch.

Why web-scale companies use them

Scaling traditional databases with strong consistency and high availability is challenging in distributed environments. Many services — Amazon, Facebook, Netflix — use primary-key access instead of traditional online transaction processing (OLTP) databases.

Common use cases:

Use caseWhy key-value fits
Shopping cartsKeyed by user or session; must always accept a write
Session managementPure lookup by session ID at enormous rate
Customer preferencesSmall, per-user, no cross-record queries
Bestseller lists and sales rankPrecomputed values fetched by a single identifier
Product catalogsRead-dominated lookups by product key

What this chapter builds

The design divides into four stages, each solving one problem the previous stage created:

  1. Design a key-value store — define requirements and the API.
  2. Ensure scalability and replication — achieve scalability with consistent hashing, then replicate the partitioned data.
  3. Versioning data and achieving configurability — resolve conflicts from concurrent updates and make the system tunable.
  4. Enable fault tolerance and failure detection — survive failures and notice when they happen.

Key takeaway

A key-value store trades the query power of a database for scale, availability, and simplicity. It is the right tool when your access pattern is "fetch this one thing by its identifier" — which describes far more of the internet than people expect.

Interview signal by level

LevelWhat a strong answer sounds like
L4"A key-value store maps keys to values, like a hash table."
L5Knows the fit: "sessions and carts are pure lookup by ID, so a key-value store — no need for a relational engine."
Staff+Frames it as a distributed system: "it's a DHT — the interesting parts aren't get and put, they're how keys map to nodes as the cluster changes, and what happens to a write during a partition."

Next: pinning down exactly what we're building.

Enjoying the preview?

Create a free account to unlock the rest of this course, the in-browser judge, and live AI mock interviews.

Sign up free to continue