Choosing between DynamoDB vs MongoDB

This post compares DynamoDB vs. MongoDB, the two most popular noSQL databases.

NoSQL databases are developer friendly because data is stored in JSON-like documents that easily map to objects of a programming language. The documents (rows in SQL) can be of different structure each because no upfront definition of a schema is required. The data schema may change with each release. This is good news for developer agility. Also the speed of queries is fast because of data denormalization. However, noSQL can also become a nightmare if you have to organize that data for something downstream like reporting or ERP integrations. In the realm of narrowly defined problems data formats with a schema dominate: XML, REST, SQL.

So let’s assume we have our mind set on a noSQL solution for whatever reason. Then MongoDB and DynamoDB are the top contenders. There are a other reviews on the internet, but I found them to be biased depending on who wrote them. [1], [2].

Below is a table that compares both systems feature by feature (searchable and sortable table if you are in a hurry).

DynamoDB vs. MongoDB

 DynamoDBMongoDB
DescriptionFully managed noSQL database
in the AWS Cloud
Most popular noSQL
document database
Database modelBoth document and
key-value store
Document store
Websitehttps://aws.amazon.com/dynamodbhttps://www.mongodb.com
DeveloperAmazon, since 2012MongoDB Inc.,
since 2009
License CommercialOpen Source
Cloud hostedyesMongoDB Atlas
Implementation LanguageJavaC++
Server OShostedLinux, OS X,
Solaris, Windows
Data scheme (model enforcement)noSchema Validation
optional
Data TypesString, Boolean,Byte, Date, Calendar, Long, Integer, 
Double, Float, BigDecimal, BigInteger
String, Boolean, Date,
Timestamp, Integer, Double,
Decimal, Object, Regular Expression,
Javascript, ObjectId, Undefined,
Null, Binary data
Data Size400 KB16 MB
Queryingby key and partial keyby key, ranges, faceted search, graph traversals, geospatial, aggregations
Indexhash or range-hash, primary plus 5 local (same partition) and 5 global indexes (eventual consistency)primary and on
any field strongly
consistent always.
Indexing strategies include compound,
unique, array, partial,
TTL, geospatial,
sparse, hash, and
text
Secondary Indexyesyes
API accessAWS DynamoDB
REST API
REST API since 4.0
Supported Programming Languages.Net,ColdFusion,
Erlang,Groovy,
Java,JavaScript,
Perl,PHP,Python,
Ruby
Actionscript,C,C#,
C++,Clojure,ColdFusion,
D,Dart,Delphi,Erlang,
Go,Groovy,Haskell,
Java,JavaScript,Lisp,
Lua,MatLab,Perl,PHP,
PowerShell,Prolog,
Python,R,Ruby,Scala,
Smalltalk
Server-side scriptsnoJavascript
Triggersyes, Lambda no,
but Change Events
since 4.0 can be
used to build one
Partitioningshardingsharding
Map ReduceTight integration with AWS EMRbuilt in
Consistencyeventual (default)
and immediate
eventual and
immediate (default)
Transactionsnoyes, since 4.0
Concurrencyyesyes
In-memory capabilitiesDAXin-memory storage engine
since 3.2
User accessUsers, groups and
roles via AWS IAM
Access rights for
users and roles
MonitoringAWS CloudWatchMongoDB Atlas
tracks 100+ metrics
Backup
DR Options
On demand and continuouscontinuous, queryable
backups with
point-in-time recovery (Atlas)
Throughput Limits10k ops / sec, more
available on request
limited by hardware
PricingBased on throughput
(read, write) and index size
Based on Memory
and CPU
Free Tier250 million requests / month, 25 GB storage512 MB
Publicly Traded AMZNMDB
Prominent companiesAmazon, Samsung,
Snapchat, Netflix,
New York Times,
AdRoll, HTC,
Dropcam, Twitch
Google, UPS,
Facebook, Cisco,
eBay, BOSH, Adobe,
SAP, Forbes

So which DB is right for you?

It depends, of course, on your situation. There is a good discussion on Stack Overflow [3], but things constantly evolve and some long held opinions are not longer true.

Amazon DynamoDB

Amazon DynamoDB is a fully managed cloud NoSQL database service. Create your tables, set your throughput, after that the heavy lifting is up to Amazon (managing distributed database cluster, installing patches, configurations, partitioning, scaling, etc.).

DynamoDB supports an Event Driven Architecture by integrating with AWS Lambda. The advantage here is (asynchronous) extensibility and integration to other systems. Fine-grained user access and control is achieved with AWS Identity and Access Management (IAM).

DynamoDB regularly ranks in Gartner’s Magic Quadrant. With its recent DAX (Amazon DynamoDB Accelerator) feature, query times below 1 milli seconds are only a one-click configuration away. This is a 10 X performance improvement that opens up entire new possibilities where such hyper-speed is of the essence.

MongoDB

MongoDB is very popular with developers. It provides the ‘M’ in the so-called MEAN stack (Mongo, Express, Angular, NodeJS). One developer can build an entire application rapidly with MEAN (or React, VueJS, and similar JS frameworks). However, with time people started complaining about MongoDB that it was missing features essential to enterprise-grade applications, for instance
– no support for multi-document transactions
– no support for money type
– no support for schema validation (constraints)
– single write node (scalability bottleneck)

Over the last few years MongoDB addressed these concerns one by one. With 4.0 there is multi-document transaction support which puts it on par with SQL databases. Earlier versions saw the introduction of schema validations, and a DecimalObject data type to model money. The hosted service solution AtlasDB takes care of the management aspect, so it is not much behind DynamoDB in this respect.

Mongo has a myriad of advanced features, data types, language support, indexing strategies which DynamoDB doesn’t. It’s aggregation pipeline alone has over 100 operators for just any use case imaginable. Mongo University offers free online courses.

Conclusion

Use DynamoDB if you have a robust use case with a simplistic data model, if you care more about operational stability than sophistication. This is also a consideration if you are short on skills or staff.

Use MongoDB if you build a product with requirements that change rapidly and in unpredictable ways. MongoDB has superior features (20 MB record size, nested arrays and objects graphs, various indexing strategies, many different ways to query and aggregate) and fewer limitations. It can be used for more advanced projects. The quibbles from the past are no longer justified. With version 4.0 MongoDB has become an enterprise-grade database like Oracle back in the days. With the hosted Atlas solution you have an alternative to DynamoDB or Azure CosmosDB or Google Bigtable, you’ll be able to focus on the implementation more.

 

References

[1] Comparing DynamoDB and MongoDB (MongoDB)

[2] Dynamo vs MongoDB, Panoply

[3] DynamoDB vs MongoDB NoSQL (Stack Overflow)

Facebooktwittergoogle_pluslinkedinmailby feather