Mongo

Deploy MongoDB To Production

2 years ago · 3 min read

MongoDB is one of the most commonly used NoSQL Databases which has many attracting features that includes, being document based and also its flexible schema. Not only this but one of its highly reputed features is seamless horizontal scaling.

While you can setup and develop against it locally within a few moments in favor of docker, in this series we will tackle MongoDB in production which has tons of options, we will provide an overview, pros and cons and conclude with some recommended options.

What to look for in a production database

  1. Being Secure: which is not a option, missing with this can ruin your business before it even starts
  2. Always Available: which represents the greatest feature of MongoDB, being available and scalable
  3. Backup seamlessly: no backup, no database … just this simple

Of course, there’s other factors that may be of valid interest to you, I just picked which I mostly dealt with in practice.

Deployment Options

Note: while On-Premise may seem an option but it will not be tackled in this article, instead we will focus on cloud based deployment options

  1. AWS DocumentDB

    Provided by AWS in 2019 to be the (MongoDB compatible) database service, DocumentDB provides a seamless database provisioning process with an S3 Backup feature out of the box. The main issue I faced dealing with it, it was not fully compatible with MongoDB and it lacked many features (in my case, mainly GridFS)

    Full report: DocumentDB compatibility report
  2. MongoDB Atlas

    Fully armed service that is officially provided by MongoDB. It’s fully compatible database as a service that works seamlessly. It’s a real valid option even it’s not a cheap one but it may be worth it. My experience with it was, as many (x As A Service) you don’t have full control, in my case I got a high down time due to that, service hanged up while importing a backup even autoscaling was enabled and their support team was not very helpful, may be it depend on the case, for me I could not wait a bit as system was down.
  3. MongoDB on AWS EC2

    This is the final option that I ended up using with no issues. I had the ability to configure every single bit while keeping its cost within range, you just need a bit of configuration and security handling, denoted below:
  • Limit connection to server to only your app servers (Use its security group if hosted on AWS, which will be seamless)
  • Change database default port
  • Create a cron job to create dump of database on regular basis
  • Move backups to S3, use a configured attached IAM rule to do S3 work

That’s it for now, if you think this was helpful, please share it with your friends.

Suggestions and feedback are welcome with ❤️ at [email protected]