Amazon EC2 is a great platform to deploy and manage MongoDB. The EC2 platform is a highly functional cloud platform and provides a huge array of knobs (which can sometimes be a problem) to optimize your deployments. In this post, I’ll share six best practices for managing MongoDB servers from various deployments on AWS.
Over the years, this has consistently been an issue with Amazon EC2, however, the release of Provisioned IOPS has almost eliminated this issue entirely! If you have a production cluster for which you need consistent disk performance, use Provisioned IOPS. If you want to take it one step further and would like performance isolation between your application traffic and the disk traffic, use EBS optimized instances. Stay away from RAID unless you know what you’re doing and have the operations staff to support you in case something goes wrong.
DNS Name and IP Address
By default, the DNS name and public IP address allocated to your instance are not static. When you reboot your instance (you will eventually), you might get a different IP and DNS name. This will break the connection between your app and the database. There are a couple of ways to get around this:
- Use a static elastic IP (additional cost)
- Configure Route 53 DNS and set up your own DNS mappings
Distribute your replica sets across the availability zones in a region. This will increase the availability of your replica set, especially when AWS is doing routine maintenance. In extreme cases, you might want to deploy your replica sets across regions.
Security groups are the ‘firewall’ for your AWS platform. They’re a powerful tool and should be leveraged. Make sure you lock down access to your MongoDB servers so you don’t expose them to the internet. Ideally, only your front end or mid-tier servers have access to the database. Security groups can be used in a region, even across AWS accounts.
If your MongoDB server is up and running 365 days a year, you can achieve almost a 50% reduction in costs by purchasing reserved instances. It will require you to pay a certain amount upfront but will save you money in the long run. Reserved instances are a billing construct and can be applied to any of your running instances.
10gen Best Practices
There are also several other non functional aspects to consider while deploying MongoDB on Amazon. You can read our other post, 10 Questions to Ask and Answer When Hosting MongoDB on AWS for more details.
At ScaleGrid, we provide a single click deployment of MongoDB replica sets across availability zones or regions. Our platform automates backups and recoveries, only use Provisioned IOPS, provide easy ways for our customers to benchmark MongoDB, and also simulate failover in MongoDB clusters. If you have other questions, comments, or feature requests, we would love to hear from you. You can email us at firstname.lastname@example.org.