1. Introduction to NoSQL

What is NoSQL?

  • NoSQL stands for “Not Only SQL”, representing databases that provide flexible, non-tabular data storage.
  • Unlike traditional relational databases (SQL), NoSQL databases can store structured, semi-structured, or unstructured data.
    Example:
    • Structured Data: A database of user profiles where every user has a name, email, and age.
    • Semi-structured Data: Log files where each entry has variable attributes (e.g., error messages with different parameters).
    • Unstructured Data: Storing images, videos, or text documents as data blobs in a database.

Characteristics of NoSQL Databases:

  • Schema-less: Data can be stored without a predefined structure.

  • Horizontally Scalable: Handle increasing amounts of data by adding more servers.

  • High Performance:

    • Optimized for fast reads/writes, often at the expense of complex querying.
    • Explanation:
      • NoSQL databases prioritize speed and efficiency by storing data in a way that’s easy to retrieve but may not support intricate relationships or multi-step joins found in SQL. For example:
        • A social media feed retrieves user posts quickly without needing to calculate relationships in real-time.
        • However, performing a query like “find all users who commented on posts liked by another user” might be slower or more complex.
  • Flexible Data Models: Instead of just storing data in strict tables, multiple data models (such as key-value, document, column-family, or graph models) are all supported

Comparing NoSQL to SQL

FeatureSQL (Relational Databases)NoSQL (Non-Relational Databases)
StructureFixed schema (tables, rows)Flexible schema (JSON, key-value, etc.)
Data RelationshipsStrongly enforced relationshipsLoosely related or no relationships
ScalingVertical scaling (bigger servers)Horizontal scaling (more servers)
Query LanguageSQL (Structured Query Language)Varies by database (e.g., JSON, APIs)
Transaction SupportStrong ACID complianceEventual consistency or BASE model
Use CaseComplex queries, analyticsReal-time data, unstructured data
ExamplesMySQL, PostgreSQL, OracleMongoDB, Redis, Cassandra