Many of us have grown up using relational database management systems that used tables, rows, and columns to organize data, and relied on query languages like SQL to retrieve and store data. While it worked well for storing basic structured data, RDBMS was unable to meet the performance, scalability, and flexibility of today’s data-intensive applications. To meet this demand, NoSQL databases emerged. These databases can store unstructured data such as user and session data, logs, chats, videos, images, and data from IoT devices. There are many NoSQL databases today, out of which DynamoDB and MongoDB are among the most popular.
What is DynamoDB?
DynamoDB from Amazon is a fully managed NoSQL database that is known for its fast and predictable performance. A convenient aspect is you can offload routine administrative tasks such as hardware provisioning and cluster scaling to the DynamoDB team, so you can focus on the core aspects of your business.
With DynamoDB, you can create tables to store any kind of data, and service any level of request. In addition, you can scale up or down, your tables on a need basis without impacting performance in any way. And, of course, you get to use the AWS management console to stay on top of resource utilization and performance.
What is MongoDB?
Some of the prominent features of MongoDB are:
- Indices — You can index the fields with primary and secondary fields.
- Replica sets — It offers high availability with replica sets, and each set can act as a primary or secondary replica at any time.
- Scaling — This database scales horizontally using a process called sharding.
- File storage — MongoDB can also be used as a file storage system. It gives you the flexibility to replicate files across multiple machines.
- Capped collections — It supports fixed-size collections, also called capped collections.
These features make it a stable and popular choice for storing unstructured data.
Now that we have a fair idea of what DynamoDB and MongoDB are, let’s see how they differ.
DynamoDB vs. MongoDB
Both DynamoDB and MongoDB work well in most situations. But here are some areas where they differ.
This is one area where DynamoDB scores heavily over MongoDB.
Since DynamoDB is a part of AWS, you can simply go to the AWS console and start a wizard to create databases. It’s really that simple!
MongoDB, on the other hand, is a complete maze of instructions. It’s particularly not a good choice for novices, as many of the authentication errors are not self-explanatory. Even for experienced users, setting up MongoDB can take a few hours.
It’s complicated because there’s no clear document that tells you how to fix the errors. Though there are a few documents in the site, it’s still not helpful. And worse, most of it works only on an Ubuntu terminal. So, if you have any other operating system, be prepared to spend considerable time and effort on the setup process.
A good alternate is the paid version called MongoDB Atlas that is cloud-hosted and easier than MongoDB to install.
Here, MongoDB scores big time over DynamoDB.
You’ll have to write long pieces of code even for the simplest of tasks in DynamoDB. Here is a sample code from the AWS documentation for creating a table and uploading data. It has more than a thousand lines of code!
To top it, all basic methods in DynamoDB are asynchronous, so if you want to do synchronous programming, you’re in for a ton of frustration. Running queries is painful too as an ordinary query takes in only one parameter. Imagine a situation where you’ll have to search for all items with a certain attribute — it’s nothing but a nightmare!
Amazon recommends using a global secondary index, but that’s definitely for advanced programmers only.
MongoDB, on the other hand, is simple and easy to work. All basic methods are available in both synchronous and asynchronous forms and querying is fairly intuitive as well.
In terms of money, both DynamoDB and MongoDB are freemium, which means, it’s free until you reach a certain usage limit.
You can use DynamoDB for free within these limits.
- 25GB of indexed data storage.
- A maximum of 200 million requests per month, including 25 write capacity and 25 read capacity units respectively.
- Ability to deploy DynamoDB tables in a maximum of two AWS regions only.
If you go beyond these limits, you’ll have to pay for what you use.
MongoDB works on a similar model too. The first 25GB is free and after that you pay for what you use. This is for MongoDB stitch edition.
If you want to use MongoDB atlas, here is the pricing structure.
- M5 costs $0.035/hour.
- M10 costs $0.09/hour.
- M20 costs $0.23/hour.
- M30 costs $0.59 per hour.
Overall, DynamoDB is expensive for a high read or write capacity while MongoDB is expensive to scale up your storage needs.
Security and access
MongoDB has been in the news lately for the wrong reasons. There have been many cases of hackers accessing MongoDB databases. According to TheRegister, ransomware attackers were able to compromise more than 27,000 MongoDB databases within just a few hours. These attackers are using vulnerabilities in MongoDB such as lack of authentication and remote accessibility to delete the original database and to hold a copy of it for ransom.
But the fact is MongoDB itself is not insecure, it’s the way it’s configured and used. The default configuration is insecure and many users don’t even know it! John Matherly, the founder of Shodan, warned in 2015 about some 30,000 MongoDB databases that are vulnerable to attackers. Since then it has grown and when the ransomware attackers found the vulnerability, they quickly cashed in.
Even today, this vulnerability exists as the authentication is turned off by default. Once you enable authentication through a username and password, it’s fairly secure.
DynamoDB is a secure database, as access is granted through IAM. It also comes with the regular AWS security measures.
Which is better?
Well, it’s subjective.
DynamoDB scores high on security and storage while MongoDB scores high on ease of use. Also, if you’re programmers are comfortable with asynchronous programming, DynamoDB would be a good option.
The choice really depends on what’s important for you and your organization.
Let us know which is your choice and why in the comments section.