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.
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
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.
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.
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.
How it works, step by step
Step 1 of 41. 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.
- 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
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.
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.
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?
Knowledge check
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.