Definition: A key-value database is a type of NoSQL database that stores information as pairs: a unique key points directly to a value.
It is especially useful when you already know the key and need to retrieve data very quickly, rather than performing complex queries or joins. (AWS Builder Center)
Simple example
Think of a dictionary:
"username:123" → "Reyhaneh"
"session:abc" → "user_id=123"
"cart:123" → ["laptop", "mouse"]You give the database the key:
GET "session:abc"and it gives you the value:
"user_id=123"The database doesn’t need to search through lots of rows to find it—the key directly identifies the value.
3 examples
-
User sessions
session:8f92 → {user_id: 42, logged_in: true}When the user makes a request, you can quickly retrieve their session.
-
Caching
product:123 → {name: "Laptop", price: 1200}Instead of repeatedly querying PostgreSQL, you can temporarily keep frequently used data in a key-value store. (Couchbase)
-
Gaming leaderboard
player:987 → score: 15420The application can quickly retrieve or update a player’s score. (Dragonfly)
Common examples
-
Redis — very fast, commonly used for caching, sessions, and real-time data. (Redis)
-
Amazon DynamoDB — a managed database supporting key-value and document models. (Amazon Web Services, Inc.)
-
Memcached — commonly used for simple in-memory caching. (techtarget.com)
Easy way to remember:
Relational DB: “Find all users whose age is greater than 20.”
Document DB: “Give me this user’s document.”
Key-Value DB: “I know the key → just give me its value.”