Sobes.tech
Junior

What are NoSQL databases?

sobes.tech AI

Answer from AI

NoSQL (Not Only SQL) is a class of non-relational database management systems that use structures different from traditional fixed-schema tables. They are designed to handle large volumes of unstructured, semi-structured, and polymorphic data, providing flexible scalability and high availability.

Main categories of NoSQL databases:

  • "Key-Value Stores": Store data as key-value pairs, where the key uniquely identifies the value.
    # Example of data representation in a key-value store
    user_data = {
        "user:123": {"name": "Alice", "age": 30},
        "product:456": {"name": "Laptop", "price": 1200}
    }
    
  • "Columnar Databases": Store data by columns rather than rows. Optimized for analytical queries and processing large data volumes.
  • "Document Databases": Store data as documents (e.g., JSON, BSON, XML). Data schema is flexible.
    // Example of a document in a document database
    {
      "_id": "prod_abc",
      "name": "Smartphone",
      "brand": "XYZ",
      "specs": {
        "display": "6.5 inch",
        "camera": "48MP"
      },
      "tags": ["electronics", "mobile"]
    }
    
  • "Graph Databases": Designed for storing and processing data represented as vertices (nodes) and edges (relationships). Used for relationship analysis.

Differences from relational databases (SQL):

Characteristic Relational (SQL) NoSQL
Data schema Fixed, strict Flexible, dynamic
Scaling Vertical (increasing server capacity) Horizontal (adding servers)
Normalization High (reducing redundancy) Low (data duplication for performance)
ACID transactions Usually full support Varies (sometimes BASE)
Query language SQL Varies (often API, specific languages)

NoSQL databases are chosen for scenarios requiring high scalability, schema flexibility, fast processing of large data volumes (Big Data), working with semi-structured/unstructured data, or specific data models (e.g., graphs).