NoSQL Databases

20 min Beginner Friendly 6.1k learners

What is NoSQL?

NoSQL stands for “Not Only SQL”. It is designed for modern applications that need to handle large volumes of data, high speed, and flexible formats.

Analogy: If SQL is like an Excel sheet with fixed rows and columns, NoSQL is like a notebook 📒 where each page can have a different structure.

Types of NoSQL Databases

  • Key-Value Store: Data stored as key-value pairs. Example: Redis, DynamoDB.
  • Document Store: Data stored as JSON-like documents. Example: MongoDB, CouchDB.
  • Column Store: Data stored in columns instead of rows. Example: Cassandra, HBase.
  • Graph DB: Data stored as nodes and relationships. Example: Neo4j, JanusGraph.

Examples

MongoDB (Document Store)

{
  "_id": 1,
  "name": "Alice",
  "email": "alice@example.com",
  "orders": [
    { "product": "Laptop", "price": 1200 },
    { "product": "Mouse", "price": 25 }
  ]
}

Redis (Key-Value Store)

SET user:1000 "Alice"
HSET user:1000 name "Alice" email "alice@example.com"

Cassandra (Column Store)

CREATE TABLE orders (
  order_id UUID PRIMARY KEY,
  customer_id UUID,
  product TEXT,
  price DECIMAL
);

Neo4j (Graph DB)

CREATE (a:Person {name:"Alice"})-[:FRIEND]->(b:Person {name:"Bob"});

Advanced NoSQL Concepts

  • Sharding: Splitting data across multiple servers for scalability.
  • Replication: Keeping copies of data across servers for reliability.
  • Eventual Consistency: Updates propagate over time, but all nodes sync eventually.
  • CAP Theorem: Trade-off between Consistency, Availability, and Partition Tolerance.

Practice Quiz

Test your understanding of NoSQL:

1. Which NoSQL type is best for social networks?
2. MongoDB stores data in what format?
3. Which feature ensures high availability?
4. Which is a Column Store DB?
5. In CAP theorem, which properties are balanced?

Great Job! 🎉

Now that you understand NoSQL, explore Cloud Databases or continue with Advanced SQL.