Database Management System (DBMS) / No SQL Databases

Key-Value Stores

πŸ”‘ What is a Key-Value Store?

A Key-Value Store is the simplest type of NoSQL database.

It stores data as a collection of key-value pairs, like a dictionary or hash map.

🧱 Structure:

Key           β†’     Value
"user:123"    β†’     { "name": "Alice", "age": 24 }
"session:456" β†’     "active"
"cart:789"    β†’     [1001, 1002, 1003]
  • The key is a unique identifier.

  • The value can be:

    • A string

    • A number

    • A JSON object

    • A blob (binary data)

    • Or anything else


βš™οΈ Features of Key-Value Stores

Feature

Description

πŸ” Simple model

Only keys and values

πŸš€ Super fast

Optimized for quick read/write

βš–οΈ Highly scalable

Supports horizontal scaling easily

πŸ“š No schema

Very flexible structure

πŸ” No querying by value

Can only search by key (unless extended features are used)


🧠 Use Cases

Key-Value stores are ideal for:

Use Case

Description

βœ… Caching

Store frequently accessed data

βœ… Session Management

User sessions, login tokens

βœ… Shopping Carts

Store items in a user's cart

βœ… User Preferences

Store user settings, likes

βœ… Real-Time Counters

Page views, likes, etc.


🧰 Popular Key-Value Databases

Database

Description

πŸŸ₯ Redis

In-memory, extremely fast, supports TTL, pub/sub

🟨 Amazon DynamoDB

Fully managed, highly scalable key-value + document store

🟦 Riak KV

Distributed, fault-tolerant

⚫ Aerospike

Low latency, real-time analytics


πŸ” Example: Using Redis

SET user:1001 '{"name":"Swastika","age":22}'
GET user:1001

πŸ“Š Advantages

βœ… Advantage

Description

Ultra fast

Ideal for real-time systems

Easy to scale

Horizontally scalable

Flexible

No fixed schema

Low latency

Supports caching, quick retrieval


❌ Limitations

❌ Limitation

Description

No complex queries

You can’t search by value without custom logic

No relations

Not suited for relational data

Over-simplified

Not ideal for complex datasets or analytics

Limited querying

Most support only get/set by key