Codementor Events

Should I Select AWS DynamoDB or MongoDB?

Published Mar 29, 2018
Should I Select AWS DynamoDB or MongoDB?

If you have decided to use NoSQL for your Application on AWS Cloud, AWS DynamoDB comes as the first choice since it's the fully managed NoSQL offering by AWS. However, its worth to compare it with other NoSQL solutions to take an effective decision. I'm going to share some of the decision points to help you with doing your own analysis. However, although I have chosen MongoDB for the comparison, some of the points will also valid for any other NoSQL databases if you compare it with DynamoDB.

Managing Database

Amazon DynamoDB is the fully managed NoSQL database in AWS. When using Amazon DynamoDB, there is quite a little to manage by yourself. It is as simple as pressing a button or run a single line of code to create a table in any AWS region. DynamoDB has internal functionalities for backup and restores as well as encryption at rest. In addition, there is no entity called Database in DynamoDB which eliminates many Database related operations such as updating software, operating system & etc.

In comparison, MongoDB also comes with fully Managed solutions like MLab where you can provision a MongoDB cluster, with a push of a button, also to place the database in an AWS Datacenter where they will manage it. However, still, there are many things to do from deployment setup perspective. Some of these concerns come in when setting up secure access to the external database from Amazon where we need to setup VPN connections (Or VPC Peering).However, if you plan to setup your custom MongoDB cluster in AWS, then you need to handle concerns like, setting up Networks, Clustering, Security, Backups & etc, which can be challenging. To simplify some of the activities it is possible to externalize management certain functionalities like MongoDB backup and restore using third-party solutions.

Winner: Amazon DynamoDB

Document Size

This is one of the limitations with Amazon DynamoDB. You need to make sure the data item size is less than 400 kilobytes. Generally, it is sufficient for most of the use cases. However, MongoDB supports the much greater size of 16 megabytes.

Winner: MongoDB

Query and Indexing

This is one of the most limitations with Amazon DynamoDB. Although it provides indexes and primary key and sort key to query tables, it is limited by a huge margin to query only from predefined attributes sets (I'm not talking about SCAN operation here since it's too expensive iterating through the entire table). This is similar to the create and update operations.

One of the major challenges I see when using Amazon DynamoDB is that it requires putting considerable time and effort to design the database tables and indexes since the design of tables, indexes, keys, and attributes need to be predetermined for effective querying. With the limited query capabilities, this makes it even difficult to support query requirements in future.

In contrast, MongoDB provides a flexible API to query attributes including the nested and deep nested ones more close to a relational database.

Winner: MongoDB

Scaling Database

This is one of the major advantages of Amazon DynamoDB. It could simply scale to petabytes in size as well as to handle a huge throughput with the matter of simple configuration. This is possible since DynamoDB manages to cluster internally and offers best practices and guidelines to maintain performance to developers. It is also possible to auto-scale the DynamoDB with the minimal configuration without worrying about underlying infrastructure.

In comparison, MongoDB Managed solutions provide similar features. Also if you deploy your own MongoDB cluster in AWS, it is still possible to scale out. However, still this doesn't match the immense scale and throughput support of Amazon DynamoDB which can be given on demand.

Winner: Amazon DynamoDB

Integrations

Amazon DynamoDB is not only a database but also can become an integral part of Amazon services ecosystem where it can be integrated to many other services at different levels. Access Control using AWS IAM Policies, Integrations with API Gateway, Integrate with Amazon EMR for Analytical Processing, Streaming Data with DynamoDB Triggers and Monitoring using AWS CloudWatch are few of them apart from connecting to DynamoDB from code.

In comparison, MongoDB doesn't have that support. However, the having the ability to run MongoDB outside AWS is one of the major decision points if there is the need to run the application using the Database in a Hybrid Cloud environment.

Winner: Amazon DynamoDB

Total Cost of Ownership

This is quite difficult to compare without knowing the nature of workload towards the database system. Amazon DynamoDB can get expensive if your queries contain a listing of multiple items or updating many at a time. Since a significant amount of Amazon DynamoDB cost goes towards the throughput (Unless you have petabytes of data) for more frequent queries it can get quite expensive.

On the other hand, MongoDB will cost for the infrastructure (Or based on infrastructure, availability, and backups for external manage services) and throughput is inclusive of the pricing.

For small applications with fewer throughput requirements, AWS DynamoDB can be less inexpensive both in terms of management costs as well as operational costs.

Winner: Difficult to Decide

Conclusion

In this article, though I have compared the two database systems using several attributes, it's not a binary decision. You have to go through each of the application requirements and decide which are the most applicable concerns and which database can solve them more efficiently. Also its difficult to say one database is better than the other.

For example, for some people query limitations in DynamoDB can be the deciding factor to move to MongoDB while for others, Fully Managed Database can be the reason to move towards DynamoDB.

Discover and read more posts from Ashan Fernando
get started
post commentsBe the first to share your opinion
Show more replies