DEV Community

ScaleGrid for ScaleGrid

Posted on • Edited on • Originally published at scalegrid.io

The Best Way to Host MongoDB on DigitalOcean

MongoDB is the #3 open source database and the #1 NoSQL database in the world. It’s a cross-platform document-oriented database that uses JSON-like documents with schema, and is leveraged broadly across startup apps up to enterprise-level businesses developing modern apps. While you may assume a great majority of the cloud database deployments are run on AWS, Azure, or Google Cloud Platform, small to medium-sized businesses in particular are gravitating towards the developer-friendly cloud provider, DigitalOcean, for their hosting for MongoDB® needs. In this post, we’ll walk you through the best way to host MongoDB on DigitalOcean, including the best instance types to use, disk types, replication strategy, and managed service providers.

DigitalOcean Advantages for MongoDB

So, what makes DigitalOcean a compelling alternative to other popular MongoDB hosting providers like AWS and Azure? As mentioned above, DigitalOcean is highly developer-friendly with its simple and easy-to-understand platform - you do not need to become certified through this cloud provider to be able to get your deployment up and running with confidence. They offer SSD-based cloud hosting with straightforward pricing as well starting at just $5/month, which makes it ideal (and affordable) for developers to build, test and deploy their new applications seamlessly in the cloud. What’s most impressive is that you’re not compromising performance for cost. We ran performance tests for MongoDB on DigitalOcean vs. AWS vs. Azure and found that DigitalOcean performance was in line with, if not better, on both high throughput and low latency in the deployment.

DigitalOcean Droplets

DigitalOcean specialized in SSD-based virtual machines called Droplets that are broken down into four simple categories. The most basic Droplet is their Standard instance which uses shared CPU starting at just $5/month. While adequate for low-traffic applications, small databases, and dev/test environments, we recommend against leveraging shared clusters for your MongoDB production deployments. They also offer a dedicated CPU-Optimized Droplet which is sufficient for CPU-intensive workloads, but offer low memory which is not ideal for MongoDB hosting.

If you are deploying a medium-sized MongoDB workload, we would recommend their most popular General Purpose Droplet which is a dedicated instance that offers 4GB of memory for each vCPU. This is typically more than adequate for production deployments and high-traffic applications, and starts at $60/month for 8GB of memory, 2 vCPUs, 4TB of transfer and 25GB of SSD disk space. DigitalOcean also recently launched their Memory-Optimized Droplets which are dedicated instances that are designed for RAM-intensive applications and high-performing databases, making it an attractive solution for heavy-workload MongoDB applications.

You can deploy MongoDB on DigitalOcean in 12 datacenter regions across the world, including the United States (New York City and San Francisco), Canada, the Netherlands, Singapore, the United Kingdom, Germany, and India.

DigitalOcean Disk Types

One of the reasons MongoDB performs so well on DigitalOcean is because of their SSD disks, which are ideal for cloud database deployments. They provide great throughput that offers significant benefits for running an index on your database or repairing a machine, saving you a significant amount of time over a standard MongoDB deployment on AWS. They even offer amazingly low latency from Amazon AWS US-East to the DigitalOcean New York datacenter, which is great for applications that are running their front on mid-tier on AWS, but would like to use DigitalOcean for their MongoDB clusters.

MongoDB Replication Strategies

If you’re running MongoDB on DigitalOcean in production, it’s best practices to deploy using a replica set to ensure high availability and data redundancy for your clusters. DigitalOcean, along with AWS and Azure, offer a 99.99% uptime SLA, but while that sounds close to perfect, that 0.01% equates to 52.6 minutes of downtime in one year. That’s almost one hour where your database becomes inaccessible to your customers, visitors and employees which can have a significant impact on your customer retention and brand reputation.

MongoDB Replica Sets

Fortunately, you can highly mitigate the risk of your deployment going down with a loss of a datacenter by setting up a geographically distributed 3-node replica set for MongoDB on DigitalOcean. There are a couple options for setting up this configuration, the first being a Primary-Secondary-Arbiter setup which provides 2 data-bearing nodes and an arbiter which acts as a voting member to determine which replica should take over in the event one becomes unavailable. This is the most affordable option as the arbiter does not hold any data and costs less to deploy, but also offers 1 less node that can take over in a failover event. The optimal replication strategy would be a Primary-Secondary-Secondary setup which leverages 3 data-bearing nodes and allows you to failover to 2 separate datacenter in the event your primary region goes down.

MongoDB Sharding

MongoDB sharding is an advanced form of deployment that allows you to horizontally scale out your data across multiple machines. This is a very complex configuration to setup and manage, as each shard contains multiple replica sets, and can be distributed across different datacenter locations for high availability. Sharding is ideal for very large data sets or high throughput deployments that require more capacity that you can get with a single server. Where the typical deployment scales vertically by adding more capacity to a server when needed, sharding allows you to scale horizontally by dividing your data and load across multiple machines. Once you have your sharded environment setup, you can add more shards as needed to support your application growth.

At ScaleGrid, we offer Standalone, 2 Replicas + Arbiter, 3 Replicas and advanced Sharding configurations for hosting MongoDB on DigitalOcean under our Dedicated Hosting plan starting with a Micro plan size at $35/month up to a X4XLarge plan with 16 cores, 48GB of RAM and 950GB of storage. You can also customize your MongoDB replica set with an unlimited number of replicas for your application needs.

Managed MongoDB Hosting on DigitalOcean

Now we get down to the ultimate question - should you self-manage your MongoDB on DigitalOcean deployments or leverage a fully managed Database-as-a-Service (DBaaS) platform? The answer boils down to your time, knowledge, and all-time accessibility to handle any critical issues that come up with your deployment.

Management & Maintenance Tasks

MongoDB DBaaS platforms allow you to automate all of your time-consuming management and maintenance operations like version upgrades, scaling, free backups, restores, provisioning, deprovisioning, replication, compacting, index management, OS patching and log rotations. Depending on the size of your deployment, this may take you 1-2 days per month, up to a full-time army of MongoDB experts working around the clock. A huge benefit of leveraging a DBaaS platform is that you eliminate the risk of human error as the management operations are automated for you. It also keeps your MongoDB clusters on DigitalOcean fully secured and up-to-date so you do not open your deployments up to potential bugs or threats that can present with a neglected database.

Monitoring Performance

Monitoring is also a huge component to managing a MongoDB deployment. With a DBaaS platform, you can automate alerts on all of your key MongoDB metrics so you’re informed the moment an undesired threshold is met, and access an advanced monitoring console to analyze all of your MongoDB and OS metrics across your primary and secondary instances and over any period of time. Additionally, with a DBaaS like ScaleGrid, you can leverage the Slow Query Analyzer which allows you to visualize slow-running queries and optimize them before they start affecting your deployment performance.

Troubleshooting Support

Last, but absolutely not least, is the accessibility to support. If you have been woken up at 4:00am by a frantic call from your boss wondering why your application is down and how quickly you can get it back up, you know exactly what I’m talking about. Each minute of downtime can cause you thousands of dollars of business, and much worse, a security breach could shut your business down altogether and put an everlasting stain on your reputation. By leveraging a DBaaS platform, you can get ahead of over 90% of these critical issues, and have a team of MongoDB experts at your side 24/7 for the unavoidable 10% to help you quickly identify and resolve the issues to get your deployment back to a healthy, running state.

At ScaleGrid, we identified DigitalOcean as an up-and-coming rockstar for hosting MongoDB and cloud computing in general back in 2013, and were the first DBaaS platform to launch support for MongoDB DigitalOcean. Still today, we are the only fully managed DBaaS platform that allows you to automate your hosting for MongoDB on DigitalOcean and leverage enterprise-grade database management tools to optimize your deployment performance, security and availability in the cloud. If you’re interested in trying out some of the advanced capabilities of a DBaaS for MongoDB on DigitalOcean, you can start a free 30-day trial with no credit card required to explore the automation tools, and check out the Compare MongoDB Providers page to see how we stack up against MongoDB Atlas, mLab, ObjectRocket and Compose for MongoDB.

Top comments (0)