Skip to content
NoSQL Databases: When Relational is Not Enough 5 min

NoSQL Databases: When Relational is Not Enough

SD
ScaleDojo
May 11, 2026
5 min read1,204 words
1
NoSQL Databases: When Relational is Not Enough

Why NoSQL Exists

In 2009, Facebook was growing by millions of users per month. Their MySQL cluster was struggling with hundreds of billions of messages and schema migrations on billion-row tables that took weeks. They needed something different - not better, but different. That demand gave rise to the NoSQL movement.

NoSQL databases do not replace SQL. Each category makes a deliberate trade-off, sacrificing something relational databases guarantee in exchange for a capability that particular workload desperately needs:

NoSQL Category Map:

                         Query Flexibility
                              ^
                              |
        Document Stores       |      Relational (SQL)
        (MongoDB, Firestore)  |      (PostgreSQL, MySQL)
        Flexible schema,      |      ACID, joins, complex queries
        nested data           |
                              |
    --------------------------|------------------------> Scale
                              |
        Graph DBs             |      Wide-Column Stores
        (Neo4j, Neptune)      |      (Cassandra, ScyllaDB)
        Relationship-first    |      Massive write throughput
        traversal             |      billions of rows
                              |
        Key-Value Stores      |
        (Redis, DynamoDB)     |
        Extreme speed,        |
        simple lookups        |
                              v
                         Simplicity

Imagine you're building a social media platform.

Every second, users are:

  • Posting photos and videos

  • Liking posts

  • Writing comments

  • Sending messages

  • Following other users

  • Receiving notifications

This generates enormous amounts of rapidly changing data.

A traditional relational database can certainly store this information, but as traffic grows, you'll start facing challenges:

  • Expensive JOIN operations across multiple tables

  • Rigid schemas that make frequent changes difficult

  • Vertical scaling limitations

  • High write throughput requirements

  • Globally distributed users expecting low latency

These challenges inspired databases that could prioritize horizontal scalability, flexibility, and performance over strict relational modeling.

That's where NoSQL comes in.


What is NoSQL?

NoSQL (Not Only SQL) refers to a family of databases that do not rely solely on the relational table model.

Instead of storing data only in rows and columns, NoSQL databases can organize data as:

  • Documents

  • Key-Value pairs

  • Wide Columns

  • Graphs

Each model is optimized for different kinds of workloads.

Unlike relational databases, most NoSQL databases allow data to evolve without predefined schemas, making them highly adaptable.

What is NoSQL

Why Choose NoSQL?

Modern internet-scale applications have different priorities than traditional business software.

NoSQL databases are designed to provide:

  • Horizontal scaling across hundreds or thousands of servers

  • High availability with automatic replication

  • Flexible schemas for evolving applications

  • Fast read and write performance

  • Efficient handling of semi-structured and unstructured data

These characteristics make NoSQL particularly attractive for cloud-native and distributed systems.


Document Databases (MongoDB, CouchDB, Firestore)

How They Work

A document database stores data as JSON-like objects (documents). Each document is self-contained and can have a completely different structure from the next. No schema migrations, no ALTER TABLE commands.

// MongoDB - a product document
{
  "_id": "prod_789",
  "name": "Wireless Headphones",
  "price": 79.99,
  "specs": {
    "battery_life": "30 hours",
    "noise_canceling": true,
    "bluetooth": "5.3"
  },
  "reviews": [
    { "user": "alice", "rating": 5, "text": "Best headphones I've owned" },
    { "user": "bob", "rating": 4, "text": "Great but a bit heavy" }
  ],
  "tags": ["electronics", "audio", "wireless"]
}

// Query: find all products with 5-star reviews priced under $100
db.products.find({
  "price": { "$lt": 100 },
  "reviews.rating": 5
})

When to Use

  • Data is naturally hierarchical - blog posts with nested comments, product catalogs where each category has different attributes

  • Schema changes frequently - startups iterating fast, prototyping new features

  • You read entire documents at once rather than joining multiple tables

  • Who uses it: Netflix (content metadata), eBay (search catalogs), Forbes (CMS)


Key-Value Stores (Redis, DynamoDB, Memcached)

How They Work

The simplest possible database: give it a key, get back a value. No queries, no filters, no joins. Just raw speed. Think of it as a giant hash map.

# Redis examples - microsecond operations

# Session storage
SET session:abc123 '{"user_id": 42, "role": "admin"}' EX 3600
GET session:abc123

# Rate limiting (sliding window)
INCR rate:user:42:minute
EXPIRE rate:user:42:minute 60

# Leaderboard (sorted set)
ZADD leaderboard 2500 "player_alice"
ZADD leaderboard 3100 "player_bob"
ZRANGE leaderboard 0 9 REV WITHSCORES   # Top 10 players

# Pub/Sub messaging
PUBLISH notifications '{"type": "new_order", "id": 789}'

Redis vs DynamoDB

Redis keeps everything in memory - reads take 0.1ms. Perfect for caching, sessions, rate limiting. But data is limited by RAM. DynamoDB is disk-based but fully managed - handles millions of requests per second with single-digit millisecond latency regardless of table size. DynamoDB is for primary storage at scale; Redis is for acceleration.


Wide-Column Stores (Cassandra, ScyllaDB, HBase)

How They Work

Wide-column stores are designed for one thing: handling massive write throughput across a distributed cluster with no single point of failure. Each row can have different columns, and data is partitioned across nodes automatically.

-- Cassandra CQL - looks like SQL but the semantics are different
-- Design your table around your query pattern (not your data model)

CREATE TABLE sensor_readings (
    sensor_id text,
    reading_time timestamp,
    temperature float,
    humidity float,
    PRIMARY KEY (sensor_id, reading_time)
) WITH CLUSTERING ORDER BY (reading_time DESC);

-- Insert millions of readings per second across the cluster
INSERT INTO sensor_readings (sensor_id, reading_time, temperature, humidity)
VALUES ('sensor-42', '2024-06-15T10:30:00Z', 22.5, 65.0);

-- Recent readings for one sensor (extremely fast - single partition)
SELECT * FROM sensor_readings
WHERE sensor_id = 'sensor-42'
LIMIT 100;

When to Use

Time-series data (IoT sensors, event logs, metrics), multi-datacenter replication with no leader node, workloads needing millions of writes per second. Netflix stores trillions of events in Cassandra. Discord handles billions of messages with it. Apple runs one of the largest Cassandra deployments in the world


Graph Databases (Neo4j, Amazon Neptune)

How They Work

Graph databases store data as nodes (things) and edges (relationships). The key insight: traversing relationships is O(1) per hop regardless of database size - unlike SQL JOINs which get slower as tables grow.

// Neo4j Cypher query - find fraud patterns
// "Show me accounts that share a phone number with
//  a flagged account and made a transaction over $10K"

MATCH (flagged:Account {status: 'FLAGGED'})
      -[:HAS_PHONE]->(phone:Phone)
      <-[:HAS_PHONE]-(suspect:Account)
      -[:MADE]->(txn:Transaction)
WHERE txn.amount > 10000
RETURN suspect.name, phone.number, txn.amount

// In SQL: multiple JOINs across billions of rows = slow
// In Neo4j: traverse edges directly = milliseconds

When to Use

Social networks (friends of friends), fraud detection (suspicious connection patterns), recommendation engines (users who bought X also bought Y), knowledge graphs, network topology. LinkedIn uses graph databases for connection recommendations. Walmart uses them for product recommendations.


The Decision Matrix

Requirement                    Best Choice          Example
-----------------------------  -------------------  ----------------------
ACID + complex queries         Relational (SQL)     PostgreSQL, MySQL
Schema flexibility + nesting   Document store       MongoDB, Firestore
Sub-ms lookups + caching       Key-value store      Redis, Memcached
Managed key-value at scale     Key-value store      DynamoDB
Massive writes + multi-DC      Wide-column store    Cassandra, ScyllaDB
Relationship traversal         Graph database       Neo4j, Neptune
Full-text search               Search engine        Elasticsearch
Time-series metrics            Time-series DB       InfluxDB, TimescaleDB

Polyglot Persistence in Practice

Real systems do not choose one database. They use many:

Typical e-commerce architecture:

  User accounts + orders  -->  PostgreSQL   (ACID, relationships)
  Product catalog         -->  MongoDB      (flexible attributes per category)
  Session + cart          -->  Redis        (fast, ephemeral)
  Search                  -->  Elasticsearch (full-text, facets)
  Recommendations         -->  Neo4j        ("customers who bought...")
  Click analytics         -->  Cassandra    (massive write volume)

Each database handles what it does best.

SQL vs NoSQL

Feature

SQL Databases

NoSQL Databases

Data Model

Tables

Documents, Key-Value, Graph, Wide Column

Schema

Fixed

Flexible

Relationships

Strong

Usually embedded or application-managed

Scaling

Primarily Vertical

Horizontal

Transactions

Full ACID

Often BASE or limited ACID (varies by database)

Joins

Excellent

Usually avoided

Best For

Structured business data

Massive scale and rapidly changing data

Interview Tip

In interviews, never say 'I would use MongoDB because it is NoSQL.' Instead say: 'This workload has flexible product attributes that vary by category, so a document store avoids the schema migration pain. But I would keep order processing in PostgreSQL because we need ACID guarantees for payments.' Show that you match the database to the specific access pattern.

Key Takeaway

NoSQL is not better than SQL - it is specialized. Each category trades something you might not need for something you desperately do. The best architectures use multiple database types, each optimized for its specific workload. This is called polyglot persistence.

Enjoyed this article?

Share it with your network to help others level up their system design skills.

Discussion0

Join the Discussion

Sign in to leave comments, reply to others, or like insights.

Sign In to ScaleDojo

No comments yet. Be the first to start the thread!

Related Articles

Enjoyed this content?

Your support keeps us creating free resources

We put a lot of hours into researching and writing these guides. If it helped you, consider buying us a coffee. Every bit goes toward keeping ScaleDojo's content free and growing.

$

One-time payment via Stripe. ScaleDojo account required.

ScaleDojo Logo
Initializing ScaleDojo