A key-value store is the simplest form of a database: store a value associated with a key, retrieve the value by key. Designing one from scratch — as asked in system design interviews — requires understanding storage engines, hashing strategies, replication, and the CAP theorem trade-offs that differentiate DynamoDB, Cassandra, Redis, and etcd.
Storage Engine Options
Hash table: O(1) get/put, stored in memory. No range queries. Used by Redis, Memcached. Size is bounded by memory. LSM-tree (Log-Structured Merge tree): writes go to an in-memory memtable (sorted by key), flushed to immutable SSTable files on disk when full. Reads check the memtable, then SSTable levels from newest to oldest (with Bloom filters to skip levels). Excellent write throughput (sequential disk I/O), acceptable read throughput. Used by RocksDB, Cassandra. B-tree: on-disk balanced tree. Excellent read performance, supports range queries, moderate write performance. Used by PostgreSQL, MySQL. Key-value stores typically use hash tables for in-memory stores or LSM-trees for persistent stores.
Consistent Hashing for Distribution
Distributing keys across nodes uses consistent hashing: map keys to a hash ring [0, 2^32), assign nodes to positions on the ring, route each key to the nearest node clockwise. Adding a node only remaps O(k/n) keys. With virtual nodes (150 positions per physical node), load distributes evenly. The client library (or a routing layer) maintains the ring state and routes requests to the correct node. Cassandra partitions by the hash of the partition key using this mechanism.
Replication
For durability and availability, replicate each key to N nodes (typically N=3). In consistent hashing, the key is stored on the primary node and the next N-1 nodes clockwise on the ring. Replication modes: synchronous: write completes only when all N replicas confirm — strong consistency but higher latency. asynchronous: write returns after the primary persists — lower latency but reads from replicas may be stale. quorum: write completes when W of N replicas confirm; read from R replicas; if W+R > N, reads always see at least one node with the latest write. Cassandra’s default: W=1, R=1, N=3 — low latency, eventual consistency. For strong consistency: W=2, R=2, N=3.
Conflict Resolution
With async replication and network partitions, different replicas can have different values for the same key. Resolution strategies: Last-write-wins (LWW): the write with the highest timestamp wins. Simple but can lose data if clocks are not synchronized. DynamoDB uses LWW by default. Vector clocks: each write is annotated with a vector clock (node → counter). On conflict, the vector clocks are compared: if one dominates the other (all counts higher), it wins; if they diverge, both versions are stored and presented to the client for resolution. Amazon Dynamo (the paper) uses vector clocks; Cassandra uses LWW for simplicity.
CAP Theorem Application
Key-value stores make an explicit CAP trade-off. CP (consistency + partition tolerance): during a partition, refuse writes/reads to maintain consistency. etcd (Raft-based) is CP — it requires a quorum to process operations, becoming unavailable during partitions. AP (availability + partition tolerance): during a partition, continue serving reads and writes, accepting possible staleness. Cassandra is AP — all nodes accept writes regardless of partition; eventual consistency resolves divergence. For a key-value store used as a cache (Redis) or session store, AP is appropriate — stale reads are acceptable. For a key-value store used for configuration (etcd) or coordination, CP is required — stale reads could cause split-brain.
See also: Meta Interview Guide 2026: Facebook, Instagram, WhatsApp Engineering
See also: Uber Interview Guide 2026: Dispatch Systems, Geospatial Algorithms, and Marketplace Engineering
See also: Scale AI Interview Guide 2026: Data Infrastructure, RLHF Pipelines, and ML Engineering
See also: Airbnb Interview Guide 2026: Search Systems, Trust and Safety, and Full-Stack Engineering
See also: Databricks Interview Guide 2026: Spark Internals, Delta Lake, and Lakehouse Architecture
See also: Anthropic Interview Guide 2026: Process, Questions, and AI Safety
See also: Atlassian Interview Guide
See also: Coinbase Interview Guide
See also: Shopify Interview Guide
See also: Snap Interview Guide
See also: Lyft Interview Guide 2026: Rideshare Engineering, Real-Time Dispatch, and Safety Systems
See also: Stripe Interview Guide 2026: Process, Bug Bash Round, and Payment Systems