NOSQL

TOPICS
  • 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:

  1. Document-Based Database
  2. Key-value Stores
  3. Graph Databases
  4. 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:


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:


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:


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:

UserIDPersonal Info (column family)Preferences (column family)
1name: Alice, age: 30language: English, theme: dark
2name: Boblanguage: 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:

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

FeatureSQL (Relational DB)NoSQL (Non-relational DB)
Data modelTables with rows and columnsDocuments, key-values, graphs, etc.
SchemaFixed and predefinedFlexible or schema-less
JoinsSupportedUsually not supported or limited
ScalingVertical (scale up)Horizontal (scale out)
Query LanguageSQLVaries (JSON queries, API calls, etc.)
Best forStructured, relational dataUnstructured 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

Popular posts from this blog

"Don't Believe Everything You Think"-Joseph Nguyen

HOW JAVA WORKS

How Java Works (Interview Question Answers)