MongoDB vs. DynamoDB: Which NoSQL Database Should You Use?
MongoDB and DynamoDB are two popular choices on NoSQL databases. Both have excellent features to support business needs. MongoDB vs. DynamoDB: How do you choose between them? The right choice really depends on your technology requirements, your cost budget, and your team members’ coding preference etc. Let’s take a close look at these databases.
What is MongoDB and MongoDB Atlas?
MongoDB is a free and open-source cross-platform document-oriented NoSQL database program:
- Uses JSON-like documents with schemas.
- Developed by MongoDB Inc.
- Published under a combination of the GNU Affero General Public License and the Apache License.
MongoDB Atlas is MongoDB’s cloud version that supports on AWS, Azure, and GCP:
- A fully automated cloud service engineered. Similarly to AWS DynamoDB. Such as on infrastructure provisioning, database setup, ensuring availability, global distribution, backups, and more.
- Also has an easy-to-use UI and API. So you can spend more time building your applications and less time managing your database.
What is DynamoDB?
AWS DynamoDB is a fully managed proprietary NoSQL database service:
- Lets you offload the administrative burdens of operating and scaling a distributed database.
- DynamoDB supports key-value and document data structures.
- Offered by Amazon.com as part of the Amazon Web Services portfolio.
Key Concepts Comparison
|Terminology||Table/Item/Attribute/Primary Key/Secondary Key||Collection/Document/Field/Primary Key/Secondary Key|
|Data Model||Key-value and document data with JSON support||BSON(JSON-like) document|
||Automatically assigned to a document upon insert|
|Backup||DynamoDB has DynamoDB Streams with point-in-time recovery||MongoDB Atlas includes continuous, queryable backups with point-in-time recovery|
|Replication||DynamoDB synchronously replicates data across three facilities in an AWS Region. DynamoDB provides DynamoDB Streams with Global Table option.||MongoDB automatically maintains replica sets, multiple copies of data that are distributed across servers, racks and data centers.|
Installation and Setup
There is no installation of AWS DynamoDB since AWS DynamoDB is one of AWS service.:
- The table setup is very easy through the user-friend DynamoDB management console, AWS CLI command or AWS API. You can start to run the table on DynamoDB in 5 minutes!
- To increase throughput, you only need to go to DynamoDB management console to click a button.
- You can enable Auto Scaling to handle sudden increases in traffic without request throttling. Auto Scaling will also decrease the throughput when the workload decreases so that you don’t pay for unused provisioned capacity.
Well, MongoDB installation is another story:
- The installation is not an easy process.
- Most of them work only on an Ubuntu terminal. So when you run into a problem in any other operating system, you do need help from a dedicated IT professional. The person who is familiar with your environment and MongoDB.
- Furthermore, there are more challenges on MongoDB sharded solution for performance and replica sets for high availability.
- Therefore, the paid solution MongoDB Atlas maybe release yourself from the installation and setup stress.
Two things I need to point out when you’re programming on DynamoDB:
- It only supports asynchronous programming. But there are lots of code templates and good documents. So you can start to run your codes in a very short time.
- It doesn’t support aggregation function. So if you want to do aggregation on DynamoDB, you could export data to AWS Redshift or AWS EMR. Then do it over there. Or enable DynamoDB Streams. Then execute the triggers of Lambda functions to populate aggregation data into a separated table.
MongoDB, on the other hand, supports both synchronous and asynchronous programming. Also, it provides three ways to perform aggregation: the aggregation pipeline, the map-reduce function, and single purpose aggregation methods.
Both have comprehensive security defined such as encryption at rest, authentication, and access control. From the security configuration standpoint, DynamoDB is easier than MongoDB:
- DynamoDB uses AWS IAM (Identity and Access Management)to configure security through the user-friendly console.
- MongoDB provides both MongoDB security checklist and MongoDB Atlas cloud security setup for you to follow. Setup security on MongoDB does take times.
- One thing I like AWS is that you can build the serverless web application to access DynamoDB. You can even add AWS Cognito to manage users access. Or setup web identity federation with identity provider for authentication and authorization.
- Even MongoDB has MongoDB Stitch to support serverless platform. But it is a separated product from MongoDB Atlas. I didn’t figure out how to combine these two MongoDB products into one cloud system.
DynamoDB and MongoDB Atlas both offer free to start for learning, prototyping, and early development. Both are freemium after the free trial which means it’s free until you reach a certain usage limit. You can estimate your cost with their cost calculators:
- DynamoDB calculator is complicated due-to AWS pay-as-you-go approach on the following charges
- Indexed Data Storage
- Provisioned Throughput Capacity
- DynamoDB Streams
- Data Transfer
- Global Tables
- Backup and Restore
- Plus other AWS services if you need (e.g. SNS, CloudWatch, Lambda)
- MongoDB Atlas calculator is relatively straightforward on the following charges
- Data Storage
- Data Transfer
- Add-on services: snapshot and backup
Now, let’s do the cost estimate on both databases:
- For example, if you deploy MongoDB on AWS US East (N. Virginia) with a 3-node replica set of M40s and run it 24/7 for one month using the included 80GB of standard block storage. The costs would be $946.79
- If you apply the similar requirements to AWS DynamoDB on the US East (N. Virginia) region: perform 5 million writes and 5 million strongly consistent reads per day on a DynamoDB table with 1KB per item. Data storage is 80 GB of data and deploys into 2 regions. Assume 160GB data storage for both backup and restore. The costs would be $190.18 plus other AWS services.
Overall, from the above examples, the cost of DynamoDB is much cheaper than MongoDB. However, if the read and write capacity and/or the item’s size are increased, the cost of DynamoDB will be increased. MongoDB Atlas is, on the other hand, the cost stays the same until you scale up the storage needs.
In conclusion, DynamoDB and MongoDB are both good choices for NoSQL databases. Both can provide business needs. DynamoDB starts with lower cost. Easy setup and maintenance on security and tables. MongoDB provides more features such as data validation, indexing strategy, query operation, and more data types. But it also costs more to start. DynamoDB uses asynchronous programming with the great coding document. However, if the developers are uncomfortable with asynchronous programming, then MongoDB may be a good option. So the choice really depends on what your needs, cost budget including the potential long-term costs, and programming experience. The good way to find out is to try the free trial on both before making the decision.
- Hands-on with DynamoDB
- AWS Data Warehouse – Build with Redshift and QuickSight
- AWS Relational Database Solution: Hands-on with AWS RDS
- Which is Right Hadoop Solution for You?
- Apache Hadoop Ecosystem Cheat Sheet
- Data Storage for Big Data: Aurora, Redshift or Hadoop?
- AWS Kinesis Data Streams vs. Kinesis Data Firehose
- Streaming Platforms: Apache Kafka vs. AWS Kinesis
- AWS Machine Learning on AWS Redshift Data
- Why Use AWS Redshift Spectrum with Data Lake
- How to Design AWS DynamoDB Data Modeling
- When Should Use Amazon DynamoDB Accelerator (AWS DAX)?
- Web Application with Aurora Serverless Cluster
- Top IT Certifications for 2018
- How I Passed AWS CSAA in 3 Months
- How to Pass AWS Certified Big Data Specialty
- AWS Elastic Beanstalk or AWS Elastic Container Service for Kubernetes (AWS EKS)
- How to Use AWS CodeStar to Manage Lambda Java Project from Source to Test Locally