Azure Cosmos DB for MongoDB
I am Suniti ( LinkedIn ), a Microsoft Learn Student Ambassador, in this blog, we will delve into the key features and benefits of Azure Cosmos DB for MongoDB, guiding developers on choosing the right architecture for scaling modern applications.
Let’s say your app is a social media platform for artists, where users can upload and share artwork, write posts, and interact through comments and likes. The app quickly gains popularity, especially after a few high-profile artists start using it and talking about it online. Suddenly, thousands of new users are signing up every hour, and your existing MongoDB infrastructure can’t keep up with the massive increase in traffic. By using Azure Cosmos DB for MongoDB, you can keep using your familiar MongoDB tools while benefiting from a highly scalable, globally available, and cost-efficient solution—allowing you to focus on improving your app, rather than worrying about infrastructure limitations.
Now, you have two architecture options for scaling your MongoDB app using Azure Cosmos DB for MongoDB : vCore Architecture and Request Unit (RU) Architecture.
1. vCore Architecture:
This option provides dedicated instances for your MongoDB app, offering a familiar scaling and seamless integration with Azure services, for users with existing MongoDB knowledge.
Seamless AI Integration: Let’s say your platform is introducing an AI feature that recommends artwork based on user preferences. With Integrated Vector Database, you can store both transactional data (user uploads, comments) and vector data (AI-generated recommendations) in the same database. This removes the complexity and cost of sending data between services, streamlining AI integration.
Efficient Text Search: Artists often search for specific keywords, like “abstract,” to find similar work. Using Text Indexes, you can enhance these searches across your MongoDB collections, ensuring quick, relevant results without extra complexity.
Vertical Scaling with No Shard Key: If your app grows and hits massive data sizes, you can scale vertically without worrying about defining a shard key, simplifying development and saving time. For example, as users upload larger and more high-resolution artwork, your database can scale effortlessly without requiring additional management.
Cost-Efficiency with Familiar Pricing: You pay based on compute (vCores & RAM) and storage (disks). So, if you’ve already been using MongoDB, you don’t have to adjust to a new pricing model. The flat pricing makes it easier to manage your costs as your platform grows.
Backup and Restore: With 35 days of backups and point-in-time restore (PITR), you’re protected from data loss, even if something goes wrong. For example, if a user accidentally deletes their profile, you can easily restore their data from a backup.
2. Request Unit (RU) Architecture:
This architecture is ideal for cloud-native apps and offers a flexible and dynamic scaling approach.
Instant Scalability: As influencers drive traffic spikes on your platform, the Autoscale feature dynamically adjusts capacity to handle the influx. Unlike other services that may take hours to scale up, Azure Cosmos DB can handle your increased traffic instantly, ensuring users don’t experience delays.
Automatic Sharding: As your platform grows and your database expands, automatic and transparent sharding ensures that scaling happens behind the scenes. This means you won’t have to manually manage or configure shards as your app grows to handle millions of users horizontally.
High Availability and Global Access: With Five 9’s (99.999%) availability and an active-active database, your app will continue to run even if part of the infrastructure fails. For example, if users from different regions are uploading artwork simultaneously, Azure Cosmos DB ensures there’s no single point of failure, and data is always accessible. MongoDB global clusters only support active-passive deployments for writes for the same data.
Real-Time Analytics (HTAP) : Your app’s dashboard tracks user engagement, and you want to run real-time analytics to see which types of artworks are gaining the most attraction. With Azure Synapse Link, you can do this without affecting the performance of your platform, allowing you to generate instant reports on user behaviour.
Serverless Deployments: When traffic is low, such as during off-peak hours, the serverless capacity mode means you only pay for the operations performed. If no users are uploading art at 3 a.m., you’re not paying for unused resources, making it highly cost-efficient.
Which Architecture, Should You Choose? 🤔
Choose vCore-based if:
You’re migrating an existing MongoDB workload or building a new MongoDB application.
Your workload involves long-running queries, complex aggregation pipelines, distributed transactions, or joins.
Your application requires 99.995% availability.
You need native support for storing and searching vector embeddings.
Choose RU-based if:
You’re developing new cloud-native MongoDB apps or refactoring existing apps for cloud-native environments.
Your workload focuses on point reads (fetching a single item by its _id and shard key) and has fewer long-running queries or complex aggregation operations.
You need unlimited horizontal scalability, instant scale-up, and precise throughput control.
Your application demands industry-leading 99.999% availability.
Both options ensure your app can handle growing traffic, provide high availability, and optimize costs based on your specific needs.
Why Cosmos DB ?
Azure Cosmos DB and MongoDB are both NoSQL databases that are highly available, scalable, and globally distributed. However, they have different strengths and weaknesses, here let’s discuss about why to move to Cosmos DB for MongoDB:
Highest uptime SLA for MongoDB offered by Cosmos DB
Instant up/down scaling with zero warm up period
Native integration with Azure Synapse Link for analytics
Cosmos DB supports multiple data models within a single database
Scalability in Azure Cosmos DB for MongoDB –
Horizontal Scaling – data and operations are split throughout a group of machines. The process of splitting the data is called sharding. It has no limits, you can data across multiple servers and data centres, Cosmos DB for MongoDB automatically manages, it for you.
Vertical Scaling – is achieved by upgrading to larger and larger machines, this will hit limits.
Integration with Azure : Azure Cosmos DB for MongoDB integrates with the Azure ecosystem, allowing developers to use their existing MongoDB tools and applications.
Conclusion
Azure Cosmos DB is a fully managed database solution designed for modern app development, supporting NoSQL, relational, and vector data models. It delivers single-digit millisecond response times, automatic instant scalability, and guarantees performance at any scale. Notably, it powers ChatGPT’s dynamic scalability with high reliability and minimal maintenance.
One key advantage of Azure Cosmos DB for MongoDB is its comprehensive SLA, which covers the entire stack, including the database and underlying infrastructure. Unlike third-party MongoDB services such as MongoDB Atlas, which only cover the database and exclude services, hardware, or software provided by the cloud platform.
Refer Resources –
Introduction/Overview – Azure Cosmos DB for MongoDB | Microsoft Learn
Your MongoDB app reimagined | Microsoft Learn
Introducing Azure Cosmos DB for MongoDB vCore: Now Generally Available! – Azure Cosmos DB Blog
Introduction/Overview – Azure Cosmos DB for MongoDB (vCore) | Microsoft Learn
Choose between RU-based and vCore-based models – Azure Cosmos DB for MongoDB | Microsoft Learn
Create Your Azure Free Account Or Pay As You Go | Microsoft Azure
Use Azure Cosmos DB for Free
Analytics with Azure Synapse Link – Azure Cosmos DB | Microsoft Learn
Microsoft Tech Community – Latest Blogs –Read More