NOSQL
- What is NoSql?
- Types of Nosql
- What is Schema?
- Traditional Sql vs NoSql
- Vertical Scalability
- Horizondal Scalability
What is NoSQL?
NoSQL stands for "Not Only SQL," non-relational databases designed to store, retrieve, and manage large volumes of unstructured, semi-structured, or flexible structured data.
NoSQL databases are designed to handle:
- Unstructured or semi-structured data
- Massive volumes of data
- High-speed, high-throughput applications
NoSQL databases do not require a fixed schema and typically do not use SQL for querying.
Types of NoSQL Databases
There are four main types of NoSQL databases, each suited to different use cases:
- Document-Based Database
- Key-value Stores
- Graph Databases
- Column-family stores
1. Document-Based Databases (e.g., MongoDB, CouchDB)
- Store data in JSON-like documents.
- Each document is a self-contained unit of data.
- Ideal for: Content management systems, user profiles, product catalogs.
Example:
{
"name": "Alice",
"email": "alice@example.com",
"orders": [
{ "id": 1, "item": "Book", "price": 15 },
{ "id": 2, "item": "Pen", "price": 2 }
]
}
2. Key-Value Stores (e.g., Redis, DynamoDB)
- Data stored as key-value pairs (like a big dictionary or hash map).
- Extremely fast for read/write operations.
- Ideal for: caching, session storage, real-time apps.
Example:
"session123": "{user: 'John', isLoggedIn: true}"
3. Graph Databases (e.g., Neo4j, ArangoDB)
- Use nodes (entities), edges (relationships), and properties to represent and store data.
- Nodes: Entities like people, places, and things.
- Edges: Relationships between nodes (e.g., "friend of", "purchased").
- Properties: Both nodes and edges can have key-value data.
- Ideal for: Social networks, recommendation engines, fraud detection.
Example:
Alice --friend--> Bob --follows--> Charlie
4. Column-Family Stores (e.g., Apache Cassandra, HBase)
- Store data in columns instead of rows.
- Designed for fast reading of large volumes of data.
- Ideal for: logging, IoT, and time-series data.
Example:
yamlCopyEditRow: 123
Name: Alice
Age: 30
Email: alice@example.com
UserID | Personal Info (column family) | Preferences (column family) |
---|---|---|
1 | name: Alice, age: 30 | language: English, theme: dark |
2 | name: Bob | language: Spanish |
What Is a Schema in Databases?
In traditional SQL (relational) databases like MySQL, PostgreSQL, or Oracle, a schema defines the structure of your data before you store it. This includes:
- Tables
- Columns (with data types)
- Relationships (foreign keys)
- Constraints (like
NOT NULL
,UNIQUE
, etc.)
For example:
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
age INT
);
This schema says every user must have:
- an integer
id
, - a name,
- an email,
- and, optionally, an age.
You must follow this structure when adding data. If your data doesn’t match this schema, the database will reject it.
Traditional SQL vs. NoSQL
Feature | SQL (Relational DB) | NoSQL (Non-relational DB) |
---|---|---|
Data model | Tables with rows and columns | Documents, key-values, graphs, etc. |
Schema | Fixed and predefined | Flexible or schema-less |
Joins | Supported | Usually not supported or limited |
Scaling | Vertical (scale up) | Horizontal (scale out) |
Query Language | SQL | Varies (JSON queries, API calls, etc.) |
Best for | Structured, relational data | Unstructured or rapidly changing data |
Vertical Scalability (Scale Up)
- Adding more power (CPU, RAM, SSD) to one server.
- Common in SQL databases.
- Has physical limits (you can’t upgrade forever).
- Gets expensive as upgrades are high-end hardware.
Example: You upgrade a machine from 16GB to 64GB RAM to handle more database queries.
Horizontal Scalability (Scale Out)
- Add more servers/nodes instead of upgrading one.
- NoSQL databases are designed to work on clusters of machines.
- They can distribute data across many machines.
- Helps in handling huge amounts of data or high user loads.
Example: You have 10 servers, and your NoSQL database automatically stores part of the data on each one.
Comments
Post a Comment