A giant dictionary: give a key, get a value, very fast (Redis, DynamoDB).
A key-value database is a giant dictionary. You put a value under a key, and later get it back by that same key. Nothing more.
Think of the dict in Python or the Map in JavaScript, but shared by many servers and able to survive a restart. The key is a string like user:42. The value can be anything: text, a number, a JSON blob, an image thumbnail.
The database hashes the key (turns it into a number) and uses that number to find the right machine, called a partition or node. One hash, one machine, one lookup. That is why it is fast, and why it scales so well: adding machines adds capacity.
| Kind | How it keeps data | Good for |
|---|---|---|
| In-memory | All data in RAM. Optional snapshots or a log on disk. (Redis, Memcached) | Caches, sessions, counters, leaderboards. Fastest, but memory is costly. |
| Persistent on disk | Data on SSD, often with a cache in front. (DynamoDB, Riak, Aerospike) | Primary data at huge scale with steady latency. |
| Embedded engines | A library inside your process. (RocksDB, LevelDB) | The building block inside other databases. |
| Consistent coordination stores | Small, strongly consistent data replicated with a consensus protocol. (etcd, ZooKeeper) | Config, locks, leader election. Not for big data. |
| Method | Idea | Note |
|---|---|---|
| Hash mod N | partition = hash(key) mod N. | Simple, but changing N moves almost every key. |
| Consistent hashing | Keys and nodes sit on a ring. A key belongs to the next node. | Adding a node moves only a small share of keys. |
| Hash slots | A fixed number of slots (Redis Cluster has 16,384) map to nodes. Move slots, not keys. | Easy to rebalance. |
| Range partitioning | Keys are split by sorted ranges. | Allows range scans, but can create hot ranges. |
A simulated clock and a fixed hash, so the picture is the same every time. Real stores use stronger hashes and often consistent hashing or hash slots (Redis Cluster has 16,384) instead of a plain modulo, so that adding a machine does not reshuffle every key.
SET session:ab91 "{user:42}" EX 1800 # value + expire in 30 minutes
GET session:ab91
INCR rate:user:42:2026-12-02T10:15 # atomic counter
EXPIRE rate:user:42:2026-12-02T10:15 60
DEL session:ab91| Term | Meaning in easy words |
|---|---|
| Key | The unique name you use to find a value |
| Value | The data stored under a key. The database usually treats it as opaque bytes |
| Hash function | A function that turns a key into a number in a repeatable way |
| Partition / node | One machine (or slice of the key space) that stores part of the data |
| TTL | Time to live: after this time the key is removed |
| Hot key | A key that gets far more traffic than others |
| Consistent hashing | A way to place keys so adding or removing a node moves few of them |
| Hash slot | One of a fixed number of buckets (Redis Cluster: 16,384) that keys are assigned to |
| Eviction | Removing keys when memory is full (see Cache Eviction Policies) |
| Persistence | Saving in-memory data to disk, for example snapshots or an append-only log |
| Atomic operation | An operation that cannot be seen half-done, such as INCR |
| Choice | We gain | We lose |
|---|---|---|
| In-memory | Lowest latency | Cost per GB, and risk of data loss if not persisted |
| On disk | Larger and cheaper data | A little more latency |
| Persistence on | Survives restarts | Extra disk work, slower writes |
| Replicas | Availability and read capacity | Possible stale reads, extra cost |
| Small values | Speed | More keys to manage |
| Eventual consistency (DynamoDB default read) | Cheaper and faster reads | A read may be a moment old (strong reads are optional) |