Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 37/ 160
02. Advanced SQL & Relational Databases

NoSQL Databases Overview (Document: MongoDB, Key-Value: Redis, Wide-Column: Cassandra)

Compare document, key-value, and wide-column stores to know when they beat or complement SQL.

IntermediateMongoDB · Redis · Cassandra3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Dominant key, item, and range query. Next, durable authority versus fast cache. Finally, backups, TTL, compaction, failover, and hot keys.

Think of it like…

The stores are specialized depots: folders keep related papers together, lockers retrieve by a label instantly, and column shelves require an exact aisle key to scale to huge inventory.

Where you’ve seen it

Use MongoDB for nested content by document_id, Redis for TTL rate counters, and Cassandra for device events keyed (device_id, bucket_day, event_time DESC) rather than arbitrary ad hoc analytics.

Words you’ll hear

MongoDB
A document database that stores BSON records and supports secondary indexes, aggregation, and replica-set consistency choices.
Redis
An in-memory data-structure server commonly used for cache, counters, queues, and ephemeral coordination with configurable persistence.
Cassandra
A masterless wide-column store whose partition key and clustering columns determine distribution and efficient query order.
Operational boundary
Choosing a store by popularity rather than access pattern creates expensive scatter queries, weak cross-document constraints, unplanned cache loss, or Cassandra partitions that become hotspots. Begin with read/write shape, consistency need, item/cardinality, latency, and recovery; model around the dominant key path, keep relational invariants in an authoritative store, and benchmark failure as well as peak throughput.

Visual diagram

Loading interactive diagram

Theory & deep dive

MongoDB: the working mechanism

MongoDB stores document-shaped aggregates, Redis provides in-memory key/value and data-structure access, and Cassandra distributes wide-column partitions for high-volume, query-pattern-driven writes.

Dominant key, item, and range query. Durable authority versus fast cache, then indexes, partitions, and replica behavior; this exposes the state governed by Cassandra.

NoSQL Databases Overview in one concrete design

Use MongoDB for nested content by document_id, Redis for TTL rate counters, and Cassandra for device events keyed (device_id, bucket_day, event_time DESC) rather than arbitrary ad hoc analytics.

Key takeaway: MongoDB stores document-shaped aggregates, Redis provides in-memory key/value and data-structure access, and Cassandra distributes wide-column partitions for high-volume, query-pattern-driven writes

NoSQL Databases Overview: failure mode and production response

Choosing a store by popularity rather than access pattern creates expensive scatter queries, weak cross-document constraints, unplanned cache loss, or Cassandra partitions that become hotspots.

Begin with read/write shape, consistency need, item/cardinality, latency, and recovery; model around the dominant key path, keep relational invariants in an authoritative store, and benchmark failure as well as peak throughput. Track Redis TTL as "missing timeouts can make cache and rate state permanent", and make Cassandra partition visible to the dataset owner.

Key takeaway: Begin with read/write shape, consistency need, item/cardinality, latency, and recovery; model around the dominant key path, keep relational invariants in an authoritative store, and benchmark failure as well as peak throughput.

How it works, step by step

Step 1 of 4
MongoDB

1. Model access

Dominant key, item, and range query. MongoDB stores document-shaped aggregates, Redis provides in-memory key/value and data-structure access, and Cassandra distributes wide-column partitions for high-volume, query-pattern-driven writes.

dominant key, item, and range query
Key numbers at this step
Redis TTL
missing timeouts can make cache and rate state permanent
Redis
An in-memory data-structure server commonly used for cache, counters, queues, and ephemeral coordination with configurable persistence.

When to use it & trade-offs

What it is

MongoDB stores document-shaped aggregates, Redis provides in-memory key/value and data-structure access, and Cassandra distributes wide-column partitions for high-volume, query-pattern-driven writes. Use MongoDB for nested content by document_id, Redis for TTL rate counters, and Cassandra for device events keyed (device_id, bucket_day, event_time DESC) rather than arbitrary ad hoc analytics.

Why it matters: Choosing a store by popularity rather than access pattern creates expensive scatter queries, weak cross-document constraints, unplanned cache loss, or Cassandra partitions that become hotspots. Begin with read/write shape, consistency need, item/cardinality, latency, and recovery; model around the dominant key path, keep relational invariants in an authoritative store, and benchmark failure as well as peak throughput.

When to reach for it

  • Compare document, key-value, and wide-column stores to know when they beat or complement SQL.
  • Choose MongoDB because it provides this capability: A document database that stores BSON records and supports secondary indexes, aggregation, and replica-set consistency choices.
  • Keep evidence for Redis TTL at "missing timeouts can make cache and rate state permanent" so the last production stage-Operate - backups, TTL, compaction, failover, and hot keys-remains testable.

When to avoid or be careful

  • Choosing a store by popularity rather than access pattern creates expensive scatter queries, weak cross-document constraints, unplanned cache loss, or Cassandra partitions that become hotspots.
  • Do not conflate Redis with MongoDB. The second concept contributes different behavior: An in-memory data-structure server commonly used for cache, counters, queues, and ephemeral coordination with configurable persistence.
  • Release only after this guardrail is in place: Begin with read/write shape, consistency need, item/cardinality, latency, and recovery; model around the dominant key path, keep relational invariants in an authoritative store, and benchmark failure as well as peak throughput.

MongoDB / Redis / Cassandra - roles, limits, and operating cost

MongoDB
Best for: A document database that stores BSON records and supports secondary indexes, aggregation, and replica-set consistency choices.

Strengths: A document database that stores BSON records and supports secondary indexes, aggregation, and replica-set consistency choices. MongoDB stores document-shaped aggregates, Redis provides in-memory key/value and data-structure access, and Cassandra distributes wide-column partitions for high-volume, query-pattern-driven writes.

Watch out: Choosing a store by popularity rather than access pattern creates expensive scatter queries, weak cross-document constraints, unplanned cache loss, or Cassandra partitions that become hotspots.

Redis
Best for: An in-memory data-structure server commonly used for cache, counters, queues, and ephemeral coordination with configurable persistence.

Strengths: An in-memory data-structure server commonly used for cache, counters, queues, and ephemeral coordination with configurable persistence. In this workflow it supports: Distribute - indexes, partitions, and replica behavior.

Watch out: The operating cost is real: keep rows and bytes per partition operationally bounded.

Cassandra
Best for: A masterless wide-column store whose partition key and clustering columns determine distribution and efficient query order.

Strengths: A masterless wide-column store whose partition key and clustering columns determine distribution and efficient query order. Its output can be checked with Replica consistency.

Watch out: Operating guardrail: Begin with read/write shape, consistency need, item/cardinality, latency, and recovery; model around the dominant key path, keep relational invariants in an authoritative store, and benchmark failure as well as peak throughput.

Interview signals & numbers to know

When this topic comes up

  • “Where is the failure boundary for MongoDB, and how would Redis TTL reveal it?”
  • “Why is Redis distinct from this behavior: a masterless wide-column store whose partition key and clustering columns determine distribution and efficient query order?”
  • Production clue: Choosing a store by popularity rather than access pattern creates expensive scatter queries, weak cross-document constraints, unplanned cache loss, or Cassandra partitions that become hotspots.
  • Design probe: Begin with read/write shape, consistency need, item/cardinality, latency, and recovery; model around the dominant key path, keep relational invariants in an authoritative store, and benchmark failure as well as peak throughput.

Benchmarks & rules of thumb

Redis TTL -
missing timeouts can make cache and rate state permanent
Cassandra partition -
keep rows and bytes per partition operationally bounded
Replica consistency -
read/write quorum must match the allowed failure model

Common mistakes & follow-ups

Common interview mistakes

  • Choosing a store by popularity rather than access pattern creates expensive scatter queries, weak cross-document constraints, unplanned cache loss, or Cassandra partitions that become hotspots.
  • Reporting success from a job exit code without checking Redis TTL and Cassandra partition.
  • Treating this example as complete without replay, rollback, or access boundaries: Use MongoDB for nested content by document_id, Redis for TTL rate counters, and Cassandra for device events keyed (device_id, bucket_day, event_time DESC) rather than arbitrary ad hoc analytics.

Likely interviewer follow-ups

  • How would you prove this contract instead of only checking that the command ran: A document database that stores BSON records and supports secondary indexes, aggregation, and replica-set consistency choices.
  • What does the recovery plan do when this occurs? Choosing a store by popularity rather than access pattern creates expensive scatter queries, weak cross-document constraints, unplanned cache loss, or Cassandra partitions that become hotspots.
  • When is MongoDB insufficient for Cassandra partition, and what does adding Redis cost in Redis TTL?
Interview tip: Lead with the data path and failure boundary: MongoDB stores document-shaped aggregates, Redis provides in-memory key/value and data-structure access, and Cassandra distributes wide-column partitions for high-volume, query-pattern-driven writes. Then make the answer operational: Begin with read/write shape, consistency need, item/cardinality, latency, and recovery; model around the dominant key path, keep relational invariants in an authoritative store, and benchmark failure as well as peak throughput.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply NoSQL Databases Overview (Document: MongoDB, Key-Value: Redis, Wide-Column: Cassandra) with data engineer interview Q&A and hands-on practice.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
Concurrency Control, Isolation Levels & Deadlock Resolution
Next topic
Graph Databases Basics (Neo4j & Cypher)