SYSTEMSIM
CH 06·Design a Key-Value Store
Overview

Section · Overview

Designing a key-value store

A key-value store is the simplest non-relational database: every record is a unique key bound to an opaque value. The API is two calls — put(key, value) and get(key) — and yet what sits behind that surface, when it has to scale, survive failures, and stay fast, is one of the densest chapters in distributed systems.

put(key, value)
get(key)

two calls.
that's the surface.

Key
Value
user:42:last_login
1747327200
session:9c3a…
{uid:42,role:'rw'}
cart:shopper-17
[sku-901, sku-742]
feature:dark_mode
on
rate:ip:10.0.4.7
3

Behind the surface

  • · keys are unique
  • · values are opaque
  • · no schema, no joins
  • · must scale horizontally
  • · must survive node loss
Fig 6-1 · the key-value contract

This module walks the design space the book opens up. Each section keeps a single idea in view; the two Live Labs at the end let you feel the consequences of the decisions interactively.

The shape of the chapter

  1. 01Single-server baseline — hash table + tiered storage
  2. 02CAP theorem — pick two when the network breaks
  3. 03Data partition — reuse the Ch5 hash ring
  4. 04Data replication — N copies, walked clockwise
  5. 05Consistency & quorum — the N · W · R math
  6. 06Vector clocks — versioning & conflict resolution
  7. 07Failure handling — gossip · sloppy quorum · anti-entropy
  8. 08System architecture — every node, every responsibility
  9. 09Storage engine — LSM write path, Bloom read path
  10. 10Wrap-up — Dynamo, Cassandra, BigTable mapped

Seven non-negotiable design goals

Every decision in the rest of the chapter trades one of these goals against another. Holding all seven simultaneously is impossible — CAP makes sure of it — so the design picks a point in the space and owns the consequences.

01

Small KV size

values fit < 10 KB

02

Big data capability

partition across nodes

03

High availability

replicate · sloppy quorum

04

High scalability

consistent hashing

05

Automatic scaling

add/remove on the fly

N·W·R
06

Tunable consistency

N · W · R per request

07

Low latency

in-memory + LSM

Fig 6-2 · the seven goals and how each is earned

Two Live Labs in this same module

After the reference walkthrough, the Quorum Playground lets you slide N, W, R and watch consistency emerge or break in real time; the Merkle Tree Sync lab shows two diverged replicas reconciling without shipping their full keyspaces.