NoSQL databases - Cassandra vs DynamoDB vs MongoDB vs CockroachDB#
The four most-cited modern non-Postgres stores. Each row is a real axis of difference.
Side-by-side#
| Cassandra / ScyllaDB | DynamoDB | MongoDB | CockroachDB | |
|---|---|---|---|---|
| Data model | wide-column, partition-key + clustering | key-value + secondary indexes | document (BSON) | relational (SQL) |
| Consistency | tunable (R + W > N) | tunable (eventual / strong) | tunable (read/write concerns) | serializable by default |
| Multi-region writes | yes (eventually consistent) | yes (Global Tables, last-writer-wins) | yes (replica sets cross-region; one leader) | yes (Raft per range, serializable) |
| Transactions | LWT (Paxos), expensive | single-item + transactions API | multi-doc, multi-shard | full SQL ACID |
| Sharding | hash ring (consistent hashing) | hash (partition key) | hashed / ranged shards | range-based, auto-rebalance |
| Joins | no | no (single-table design) | $lookup (limited) | full SQL |
| Operations | high (DC, gossip, repair) | none (fully managed) | medium (replica set ops) | medium (cluster, but no master) |
| Cost shape | per-node | per-request + storage | per-cluster / Atlas | per-node |
| Query flexibility | partition-key bound | partition-key bound | rich (any field, but watch indexes) | full SQL |
| Strong points | linear write scale, no master | hands-off, predictable, dynamic | flexible schema, rich querying | global SQL with serializability |
Quick chooser#
flowchart TB
Q[NoSQL choice]
Q --> A{Need SQL semantics<br/>+ serializable?}
A -->|yes| CR[CockroachDB / Spanner / YugabyteDB]
A -->|no| B{Managed only,<br/>AWS-native?}
B -->|yes| DD[DynamoDB]
B -->|no| C{Schema flexible,<br/>rich queries?}
C -->|yes| MG[MongoDB]
C -->|no| CA[Cassandra / Scylla]
classDef p fill:#dbeafe,stroke:#1e40af,stroke-width:1px,color:#0f172a;
classDef s fill:#fef3c7,stroke:#92400e,stroke-width:1px,color:#0f172a;
class Q,A,B,C p;
class CR,DD,MG,CA s;
Pick by access pattern#
| Access pattern | Pick |
|---|---|
| Time-series append + range scan by time | Cassandra (wide-row) |
| Single-key lookup at huge scale, AWS | DynamoDB |
| Catalog with frequent schema changes | MongoDB |
| Banking ledger / strict invariants | CockroachDB |
| Geo-distributed shopping cart | DynamoDB Global Tables / CockroachDB |
| Mobile sync KV | DynamoDB / Couchbase |
| Real-time analytics ingestion | Cassandra + ScyllaDB |
Gotchas you should know#
- Cassandra - tombstones from deletes can wreck read latency until compaction; secondary indexes are weak; LWTs (Paxos) are slow - design around partition keys.
- DynamoDB - single-partition write cap (1k writes/s); hot partition risk; secondary indexes carry separate cost; you pay by access.
- MongoDB - sharded transactions add latency; choosing a shard key is hard to change later; aggregation can be heavy on memory.
- CockroachDB - global tables charge multi-region write latency; backups + restore at TB scale need planning; smaller community than Postgres.
Where each appears in this site#
- Cassandra patterns - see Key-value store, Discord engineering.
- DynamoDB patterns - referenced throughout the AWS-heavy designs.
- MongoDB internals - Document database.
- CockroachDB / Spanner - referenced in Multi-region & DR and Logical clocks.
Glossary & fundamentals#
| Tag | Concept | Page |
|---|---|---|
HLD |
Sharding | database-sharding |
HLD |
Consistent hashing | consistent-hashing |
HLD |
CAP / PACELC | cap-pacelc |
HLD |
MVCC & isolation levels | mvcc-isolation-levels |
HLD |
Storage engines (LSM is common here) | storage-engines-lsm-btree |
FAQ#
Should I use Cassandra or DynamoDB?#
Use DynamoDB if you are on AWS and want a fully managed key-value store with predictable latency. Use Cassandra or ScyllaDB when you need multi-cloud, write-heavy workloads, or tunable consistency knobs.
What is the difference between Cassandra and MongoDB?#
Cassandra is a wide-column store with partition keys and tunable consistency, optimised for writes. MongoDB is a document store with rich queries and secondary indexes, better for flexible read patterns.
When is CockroachDB the right choice?#
CockroachDB fits when you want PostgreSQL SQL and ACID transactions across multiple regions with serializable isolation. It costs more per write than Cassandra but removes the burden of denormalisation.
Can MongoDB replace a relational database?#
For document-shaped data with limited cross-collection joins, yes. For workloads with complex multi-table joins, foreign keys, and strict transactional needs, Postgres or CockroachDB are usually better.
Which NoSQL database scales best?#
Cassandra and ScyllaDB scale linearly to thousands of nodes with predictable write throughput. DynamoDB scales transparently but bills per request, so cost discipline matters once traffic grows.
Further reading#
- 📄 Paper - Amazon Dynamo (SOSP '07)
- 📄 Paper - Cassandra: Decentralized Structured Storage (Lakshman & Malik)
- 📄 Paper - Spanner: Google's Globally-Distributed Database (OSDI '12)
- 📑 Docs - DynamoDB - Best practices for design
- 📑 Docs - MongoDB - Sharding internals
- ✍️ Blog - CockroachDB - Serializable, lockless, distributed (SSI)
- ✍️ Blog - Jepsen - analyses (Cassandra, MongoDB, CockroachDB)