Advanced Topic 41 of 51 Databases
Key-Value Stores
Simple stores mapping keys to opaque values.
How it works
A key-value store is the simplest NoSQL model: a dictionary mapping unique keys to opaque values, with operations get, put and delete in O(1) average time. Stores may be in memory, like Redis and Memcached, or persistent, like RocksDB, DynamoDB and etcd, and often add expiry, atomic counters, lists, sets and transactions. They scale horizontally by partitioning keys with hashing.
Step-by-step walkthrough
- put(session:42, data) stores a value under a key.
- The store hashes the key.
- get(session:42) returns the value in constant time.
- The value is opaque, no queries inside it.
- Ideal for caches and sessions, as in Redis.
Where it is used
Caching, session storage, rate limiting, leaderboards, feature flags, configuration and message queues use key-value stores for extremely low latency.
Common pitfall
Without a query language, you can only look up by key, so ad hoc queries and range scans may be hard. Hot keys overload one node. Cached values can go stale and need invalidation or time-to-live policies. In-memory stores can lose data without persistence, so plan durability, key naming schemes and memory limits.
Where it fits in the course
Key-Value Stores is topic 41 of 51 in Databases, rated Advanced. It follows Document Stores. The next topic is Column-Family Stores.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Databases quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Databases quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Key-Value Stores?
Where do people use Key-Value Stores?
What is the most common mistake with Key-Value Stores?
What should I learn before this topic?
How can I practice it?
Is Key-Value Stores hard to learn?
How long does it take to learn Key-Value Stores?
Which topics are related to Key-Value Stores?
What should I study after Key-Value Stores?
Related topics
- Document Stores (Databases)
- Column-Family Stores (Databases)
- NoSQL Databases (Databases)
- Graph Databases (Databases)
- Expected Value (Math for Computing)
- Pass by Value vs Reference (Programming Fundamentals)
- Singular Value Decomposition (Math for Computing)