Agentic AI Engineering with Python: Live Course
System DesignDatabases

Types of NoSQL Databases


NoSQL databases provide alternative ways of storing and retrieving data, allowing systems to achieve better scalability, flexibility, and performance.

NoSQL databases are categorized into four main types based on how they store and retrieve data:

  1. Key-Value Databases
  2. Columnar Databases
  3. Graph Databases
  4. Document Databases

Each type solves a different set of problems and is widely used in modern system design


Key-Value Pair Database

A Key-Value database stores data in the form of a unique key and its corresponding value.

  • Key - Must be unique (acts as an identifier)
  • Value - Can contain any type of data

Supported Value Types

Value TypeExample
String"hello world"
Number42, 3.14
JSON{"name": "Alice"}
Array[1, 2, 3]
ObjectNested objects
BLOBBinary large objects (images)
Byte[]Raw byte arrays

Key Characteristics

  • No fixed structure required
  • No relationships to maintain
  • Values can be nested objects, arrays, or combinations of multiple data types

Example: Blog Post Stored as Key-Value

{
  "posts": [
    {
      "post_id": 1,
      "content": "anyText",
      "comments": [
        {
          "comment_id": 1,
          "comment": "nice"
        }
      ]
    }
  ]
}

All related data (post + comments) lives together in a single value and no joins needed.

Key-Value_database_UseCases

  • Redis
  • Amazon DynamoDB
  • Memcached

Columnar Database

Traditional SQL databases read data row-wise (left to right). Columnar databases read data column-wise (top to bottom), enabling efficient aggregation and analytics.

How Does It Work?

Students Table:

idnamemarks
1Alice85
2Bob72
3Charlie90

Task: Calculate the average marks of the class.

ApproachHow It ReadsEfficiency
SQL (Row-wise)Reads id, name, marks for every rowReads unnecessary columns (id, name)
Columnar DBReads only the marks column: [85, 72, 90]Reads only what's needed

Key Characteristics

OperationPerformanceReason
ReadingFasterOnly relevant columns are scanned
WritingSlowerData must be written column by column (id → name → marks → ...)

Use Cases

  • Data analytics and aggregations
  • Business intelligence and reporting
  • Large-scale data warehousing

Columnar_databases_UseCases

DatabaseCompany
BigQueryGoogle
RedShiftAmazon
SnowflakeSnowflake Inc.

Columnar DBs are optimized for read-heavy analytical workloads, not for frequent writes, because data must be written separately into different column structures like id column, name column, and marks column.


Graph Database

Data is represented as nodes (entities) connected by edges (relationships). Both nodes and edges can have properties.

ComponentRepresentsCan Have Properties?Examples
NodeRepresents an entity (data)YesStudent, Course, User
EdgeRepresents a relationship between nodes.YesStudent --> Enrolled In --> Course

Example - Student-Course-College System

[Student] --Enrolled--> [Course]
[Student] --Studies-->   [College]
[College] --Provides--> [Course]

Node Properties:

NodeProperties
Studentid, name, age, department
Courseid, name, duration, credits
Collegeid, name, location

Edge Properties:

EdgeConnectsProperties
EnrolledStudent → Courseyear, marks, year_of_passing
StudiesStudent → Collegebatch, enrollment_year
ProvidesCollege → Coursesemester, faculty

Key Characteristics

  • Two entities can have multiple different relationships
  • Entities can be connected to many other entities
  • Ideal for finding patterns and connections between data
  • Can be slower due to maintaining multiple nodes and edges with properties

Graph_databases_UseCases

  • Gremlin
  • SparQL
  • Cypher (Neo4j)

Document Database

Data is stored as documents ( JSON/BSON format). Each document can have a different structure, and thus no fixed schema is required.

Key Characteristics

  • Flexible and schema-less - each document can have different fields
  • Data can be stored with any length and structure
  • No need to follow a predefined schema
  • Retrieval of data is fast due to self-contained documents

Example - User Profiles with Varying Data

// User 1: Minimal data
{
  "user_id": "u1",
  "name": "Alice",
  "email": "alice@mail.com"
}

// User 2: Detailed data
{
  "user_id": "u2",
  "name": "Bob",
  "email": "bob@mail.com",
  "phone": "+1234567890",
  "address": { "city": "NYC", "zip": "10001" },
  "social": { "twitter": "@bob", "github": "bob-dev" }
}

Both documents coexist in the same collection despite different structures.

Document_databases_UseCases

  • MongoDB
  • CouchDB

NoSQL Database Comparison

TypeData ModelRead SpeedWrite SpeedBest For
Key-ValueKey → ValueVery FastFastCaching, sessions, simple lookups
ColumnarColumn-orientedFast (analytics)SlowAggregations, data warehousing
GraphNodes + EdgesModerateModerateRelationships, pattern detection
DocumentJSON DocumentsFastFastFlexible schemas, logging

Different_Dabatase_Usage


Summary

  • NoSQL databases are designed to address scalability, flexibility, and performance challenges that traditional relational databases may face at large scale.
  • Key-value databases provide extremely fast access and are ideal for caching and session management.
  • Columnar databases are optimized for analytical workloads and large-scale reporting systems.
  • Graph databases excel at managing and analyzing relationships between interconnected entities.
  • Document databases offer schema flexibility and are widely used for content platforms, user profiles, and modern web applications.
  • Selecting the right NoSQL database depends on the application's access patterns, scalability requirements, and data model.

Written By: Muskan Garg

How is this guide?

Last updated on