Azure Cosmos DB vs MongoDB Atlas

Michael Chudinov
6 min readJun 12, 2020

--

Comparison of features, capabilities, prices. Why to choose one or another.

I have been involved a couple of times in discussions Cosmos DB vs MongoDB Atlas. The typical questions for such discussions are:

  • What is a better choice as document storage?
  • How to compare them to decide which fits better my project needs?
  • How they performance, storage capacity and throughput scale?
  • What about backup?
  • How much does my database going to cost?

Some notes, before we start:

  • I made a simple comparison based on criteria that matter for projects I was involved in. Criteria might be different for you.
  • Cosmos DB is more then just a document storage, it has other storage engines too, but this blog post is only about its MongoDB-API storage functionality.
  • Both databases are being actively developed and situation is changing rapidly.
  • MongoDB Atlas works with multiple cloud providers (including Azure). The storage price differs between them. This affects both data storage and backup price for Atlas.
  • RU — request unit is a kind of IOPS in Cosmos DB terminology.

Storage scaling

MongoDB Atlas

Automatic storage scaling for cluster with a tier of M10 or larger.
https://docs.atlas.mongodb.com/customize-storage/#auto-scale-cluster-tier-and-storage-capacity

Cosmos DB

Automatic scaling without limit.
https://docs.microsoft.com/en-us/azure/cosmos-db/faq

Capacity (CPU/memory) scaling

MongoDB Atlas

Automatic horizontal capacity scaling for cluster with a tier of M10 or larger.
https://docs.atlas.mongodb.com/cluster-autoscaling/#cluster-autoscaling
Horizontal scaling with sharding, available only with a tier of M30 or larger.
https://docs.atlas.mongodb.com/cluster-config/sharded-cluster/#create-cluster-sharding

Cosmos DB

Automatic scaling without limit.

Throughput scaling

MongoDB Atlas

Limited by cluster size tier. Cluster supports vertical autoscaling starting with tier M10.
https://docs.atlas.mongodb.com/sizing-tier-selection

Cosmos DB

Manually limited by RUs. Potentially unlimited.
https://docs.microsoft.com/en-us/azure/cosmos-db/faq
https://docs.microsoft.com/en-us/azure/cosmos-db/scaling-throughput

Partitioning (sharding)

MongoDB Atlas

Based on user-defined key. Key can be changed (starting from v4.0).
https://docs.atlas.mongodb.com/global-cluster-sharding

Cosmos DB

Based on user-defined key. Key can not be changed.
https://docs.microsoft.com/en-us/azure/cosmos-db/partitioning-overview

Uptime

MongoDB Atlas

99.995% Guaranteed only for a tier M30 or larger.
https://www.mongodb.com/cloud/atlas/sla

Cosmos DB

99.99%
https://azure.microsoft.com/en-us/support/legal/sla/cosmos-db/v1_3

Fault tolerance

MongoDB Atlas

A minimum of three data nodes per replica set are automatically deployed across availability zones (AWS), fault domains (Azure), or zones (GCP) for continuous application uptime in the event of outages and routine maintenance.
https://www.mongodb.com/cloud/atlas/faq

Cosmos DB

Within each region, every partition is protected by a replica-set with all writes replicated and durably committed by a majority of replicas. Replicas are distributed across as many as 10–20 fault domains.
https://docs.microsoft.com/en-us/azure/cosmos-db/high-availability

Backup

MongoDB Atlas

User-defined backup policy.
On-demand snapshots.
Only with a tier of M10 or larger.
Backup costs separately, included in common bill.
https://docs.atlas.mongodb.com/backup/cloud-backup/overview

Cosmos DB

Automatic backup. Every 4 hours, keep 2 last backup. On-demand data restore, means you need to contact Azure support.
Included in price.
https://docs.microsoft.com/en-us/azure/cosmos-db/online-backup-and-restore

Archiving

MongoDB Atlas

Automatically moving data to a read-only archive. Only with a tier of M10 or larger
https://docs.atlas.mongodb.com/online-archive/manage-online-archive

Cosmos DB

not available out of the box.
Can be build with Azure functions, Azure Data Factory and so on.

Max document size

MongoDB Atlas

16MB
https://docs.mongodb.com/manual/reference/limits/

Cosmos DB

2 MB
https://docs.microsoft.com/en-us/azure/cosmos-db/concepts-limits

Tools

MongoDB Atlas

All the tools that are compatible with MongoDB.
MongoDB in Docker container for testing and development.

Cosmos DB

All the tools that are compatible with MongoDB v3.6
Azure portal with built-in storage explorer
stand alone desktop storage explorer (Windows/MacOS/Linux)
Emulator for development and testing (Windows only)

MongoDB API support

MongoDB Atlas

full support API, user-defined version, up to the latest.

https://docs.atlas.mongodb.com/cluster-config/mongodb-version

Cosmos DB

subset. Currently MongoDB v 3.6
https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-feature-support-36

Indexing

MongoDB Atlas

Indexes can be created and deleted dynamically, with some limitations.
https://docs.mongodb.com/manual/reference/limits/#index-limitations

Cosmos DB

_id field only by default.
To apply a sort to a query, you must create an index on the fields used in the sort operation.
Unique indexes can be created only when the collection is empty.
https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-indexing#creating-unique-indexes

TTL

MongoDB Atlas

yes
https://docs.mongodb.com/v4.2/tutorial/expire-data

Cosmos DB

yes. TTL consumes RUs
https://docs.microsoft.com/en-us/azure/cosmos-db/time-to-live

Consistence model

MongoDB Atlas

https://docs.mongodb.com/manual/core/read-isolation-consistency-recency

Cosmos DB

5 levels. The higher the level, the more RUs it uses, then price is higher.
https://docs.microsoft.com/en-us/azure/cosmos-db/consistency-levels

Customer support

MongoDB Atlas

Basic plan included, but has no response time SLA.
Developer plan 49 USD/month.
Cloud provider support is probably needed anyway.
https://www.mongodb.com/pricing

Cosmos DB

Included in Azure support plan. Standard plan is $100 per month
https://azure.microsoft.com/en-us/support/plans

Global replication

MongoDB Atlas

Supported

Cosmos DB

Can be enabled at any time with just some clicks in Azure portal.

Price model

MongoDB Atlas

Predefined price per cluster per hour usage with predefined CPU/memory/storage capacity.
https://www.mongodb.com/pricing

Cosmos DB

Pay-as-you-go, per RUs and occupied storage.

Price critical factors

MongoDB Atlas

cluster memory, storage capacity

Cosmos DB

IOPS, document size, consistency level.
Writes are 5x times more expansive then reads.
https://docs.microsoft.com/en-us/azure/cosmos-db/optimize-cost-reads-writes

Price examples

MongoDB Atlas

M20 (Azure)
4GB RAM * 32GB storage
- ~160 USD/month
- support 49 USD/month
- Backup 50USD/month (depends on size)
total: ~260 USD/month

M30 (Azure)
8GB RAM * 32GB storage
~408 USD/month
- support 49 USD/month
- Backup 50 USD/month (depends on size)
total: ~508 USD/month

Cosmos DB

Calculated for a single region with https://cosmos.azure.com/capacitycalculator

32GB database
Document size 1KB
IOPS: 2500 read/s + 1000 write/s
~443 USD/month

32GB database
Document size 1KB
IOPS: 2500 read/s + 2500 write/s
~877 USD/month

32GB database
Document size 1KB
IOPS: 2500 read/s + 5000 write/s
~1590 USD/month

32GB database
Document size 10KB
IOPS: 2500 read/s + 2500 write/s
~1634 USD/month

Customer considerations

  1. In spite of attractiveness of pay-as-you-go price model for Cosmos DB and possibility to create a budget, one customer prefers predefined cluster price model from MongoDB Atlas. The customer finds predefined pricing model of MongoDB Atlas more clear and safer for budgeting.
  2. For another project the document limit size of 2MB in Cosmos DB was an impediment due to binary attachments inserted into documents. While 16MB document limit for MongoDB Atlas looks much more attractive.
  3. A government customer finds it difficult to use MongoDB Atlas for a simple reason it is one more additional service supplier. Even though customer has an agreement with Azure, so in order to use MongoDB Atlas (even over Azure) customer needs to follow bureaucratic service purchase routines and go into a new service agreement.

My conclusion so far

Cosmos DB is good for:

  1. Small documents. The smaller the cheaper. Less then 1KB is preferable.
  2. When you read more often then write, because writes are 5x times more expansive in Cosmos.
  3. Your like the idea to start small and pay-as-you-go.
  4. You have support included in Azure subscription even for a small database.
  5. You need a guaranteed latency despite of usage.

MongoDB Atlas is good for:

  1. Any size documents. And MongoDB is the only choice for documents bigger then 2MB.
  2. When you like to have a fixed budget for storage.
  3. When you use Mongo-API features that are not covered by Cosmos DB.
  4. When you need freedom to create unique indexes.
  5. When you write data more often then read, MongoDB storage will be cheaper with other equal parameters.
  6. If you want to decide backup policy.

Both solutions are good for prototyping and testing.

  • It is easy and costs nothing (read about free tier up to 400RU/s and 5GB) to start with CosmosDB. Pay-as-you-go pricing model does not require up-front investments and local storage emulator is free.
  • MongoDB Atlas has free tier for databases up to 512MB, and it is easy to run it in container on any platform.

External links

MongoDB Atlas price calculator
Cosmos DB capacity calculator
Cosmos DB price calculator

Originally published at https://blog.chudinov.net on June 12, 2020.

--

--