Rockset
Published in

Rockset

MongoDB vs DynamoDB Head-to-Head: Which Should You Choose?

We compare MongoDB and DynamoDB, their pros and cons, data types, cost, reliability, performance and security.

Databases are a key architectural component of many applications and services.

Traditionally, organizations have chosen relational databases like SQL Server, Oracle, MySQL and Postgres. Relational databases use tables and structured languages to store data. They usually have a fixed schema, strict data types and formally-defined relationships between tables using foreign keys. They’re reliable, fast and support checks and constraints that help enforce data integrity.

They aren’t perfect, though. As companies become increasingly digital, they often begin generating massive amounts of data, and they need a place to store it. Relational databases scale up well, but can be painful to scale out when a company has more data than a single database server can manage.

On the other hand, non-relational databases (commonly referred to as NoSQL databases) are flexible databases for big data and real-time web applications. These databases were born out of necessity for storing large amounts of unstructured data. NoSQL databases don’t always offer the same data integrity guarantees as a relational database, but they’re much easier to scale out across multiple servers.

NoSQL databases have become so popular that big companies rely on them to store hundreds of terabytes of data and run millions of queries per second. So why have NoSQL databases become so popular compared to traditional, relational databases?

For one, NoSQL databases can accept any type of data: structured, unstructured or semi-structured. This flexibility makes them the go-to database for many use cases. Secondly, NoSQL is schemaless, so database items can have completely different structures from one another. And as mentioned, due to their architectures, NoSQL databases are easier to scale horizontally than relational databases.

There are many NoSQL databases available in the market. Two popular options are MongoDB and Amazon DynamoDB, and architects often find themselves choosing between the two. In this article, we’ll compare MongoDB and Amazon DynamoDB to each other and highlight their significant differences. We’ll include their pros and cons, differences in data types, and discuss factors like cost, reliability, performance and security.

Before comparing MongoDB to DynamoDB, let’s take an in-depth look at each solution to understand what they are, their characteristics and their advantages and disadvantages.

In This Corner, MongoDB

MongoDB is a NoSQL, document-oriented general purpose database management system. It is optimized for low latency, high throughput, and high availability. It also supports a JavaScript-based query language to run commands and retrieve data, with official client drivers available for over a dozen programming languages. It’s a cross-platform, open-source non-relational database that stores data as collections of documents.

MongoDB uses BSON internally to store documents, which is a binary representation of JSON that fully supports all of the features of JSON with support for additional data types, more efficient compression, and easier parsability. While MongoDB collections can have a schema against which the database validates new documents, schema validation is optional.

MongoDB’s Characteristics

MongoDB is a general-purpose database. It can serve various loads and multiple purposes within an application. It also has a flexible schema design, meaning there’s no set schema to define how to store data, and it scales both vertically and horizontally. MongoDB takes into account security features such as authentication and authorization. It also has a document model that maps to objects in application code, making it easy to work with data.

MongoDB’s Pros

  • Flexibility: MongoDB has flexible database schemas. You can insert information into the database without worrying about matching criteria or data types. MongoDB supports more native data types than DynamoDB, and it lets you nest documents.
  • Systems Design: Beyond accommodating large volumes of rapidly changing structured, semi-structured and unstructured data, MongoDB enables developers to add to the schema as their needs change.
  • Data Model: Compared to DynamoDB, MongoDB supports regular JSON and advanced BSON data models such as int, long, date, timestamp, geospatial, floating-point and Decimal128.
  • Runs Anywhere: This solution can run anywhere, so users future-proof their work without fearing vendor lock-in.
  • Cost: MongoDB has a free, open-source version if you are cost conscious. They’ve also recently introduced a pay-as-you-go, serverless pricing option for MongoDB Atlas, their managed cloud offering.

MongoDB’s Cons

  • Memory Use: MongoDB needs to keep its working set in RAM to achieve acceptable performance. This reliance on RAM makes MongoDB too expensive for many use cases.
  • Data Duplication: Duplication happens because, in MongoDB, users tend to use nested documents instead of normalized tables like in a relational database. In some cases this may be due to denormalization that needs to occur because MongoDB does not support high performance JOINs, and instead uses a data that belongs together is stored together philosophy to avoid the use of JOINS entirely. This limitation can cause data sizes, and the related costs, to climb.
  • Indexing: MongoDB supports simple indexes and complex compound indexes containing multiple document properties. As with most databases, poorly designed or missing indexes can slow reads and writes, as the index must update every time someone inserts a new document in a collection.

And, in This Corner, DynamoDB

Amazon DynamoDB is a fast, flexible, NoSQL database. It’s suitable for all applications that need consistent latency at any scale. It’s a fully managed NoSQL database that’s ideal for document and key-value models. Amazon developed DynamoDB as a managed database for applications requiring similar, simple query patterns.

DynamoDB can scale on-demand to support virtually unlimited read and write operations with response time under single-digit milliseconds. It’s perfect for mobile, web, gaming and advertising technology.

DynamoDB’s Characteristics

DynamoDB is serverless and scales horizontally to support tables of any size, making it good for large-scale performance. Plus, query performance doesn’t degrade with database size when querying by key. It also has a flexible schema that enables you to quickly adapt tables as your needs change without restructuring the table schema (as required in relational databases).

DynamoDB also offers global tables, albeit at an extra cost. These tables replicate your data across AWS Regions, making it easy for your app to locally access data in the selected regions. DynamoDB also continuously backs up your data to prevent data loss. It encrypts your data for improved security, and is ideally suited for enterprise applications that have strict security requirements.

DynamoDB’s Pros

  • Customizable: The DynamoDB database can be modified according to your app’s priorities.
  • Fast: DynamoDB delivers excellent performance, no matter how many records you store or how often you query it by key.
  • Scalability: DynamoDB scales seamlessly, regardless of the traffic levels.
  • Pricing: DynamoDB uses a pay-as-you-go, throughput-based pricing technique where different inputs may affect prices. This can help to optimize your costs as they will fluctuate with your workload, but may also cause your pricing to be unpredictable.

DynamoDB’s Cons

  • Limited Query Language: DynamoDB has a limited query language compared to MongoDB. This is because DynamoDB is a key-value store and not a full document database. Every DynamoDB record has two keys: a partition key and a sort key. Every query must provide one partition key, and can optionally specify a single value or a range for the sort key. That’s it.
  • Limited Indexing: Compared to MongoDB, where indexing your data comes at no extra cost, DynamoDB indexes are limited and complex. Amazon sizes and bills the indexes separately from data.
  • Pricing: DynamoDB uses a pay-as-you-go, throughput-based pricing technique where different inputs may affect prices. This can help to optimize your costs as they will fluctuate with your workload, but may also cause your pricing to be unpredictable.

Head-to-Head Table of MongoDB vs DynamoDB

Both Amazon DynamoDB and MongoDB are widely used, highly scalable and cloud-compatible NoSQL databases. Despite these similarities, they have some key differences. The table below explores these further:

MongoDB vs DynamoDB comparison table

Which Database Should I Choose, MongoDB or DynamoDB?

DynamoDB and MongoDB are highly successful modern alternatives for traditional database systems, such as MySQL, PostgreSQL and others. When selecting your database, you need to consider factors such as scale, user requirements, deployment method, storage requirements and functionality.

If you’re looking for an AWS-native solution with MongoDB-like capabilities, you can also consider Amazon DocumentDB. While DocumentDB is not based on the MongoDB server, iIts abilities are close to MongoDB, and is compatible with the MongoDB 3.6 and 4.0 APIs. You can even use DocumentDB as a drop-in replacement for MongoDB as it is MongoDB compatible.

MongoDB and DynamoDB are both solid NoSQL databases that meet and solve various user needs. You need to carefully consider whether or not a database fully suits your use case. Each database has unique advantages, so factor in your long-term cloud strategy and an application’s specific needs when deciding which NoSQL database to select.

If you’re in need of real-time analytics for your data stored in MongoDB or DynamoDB, consider Rockset, which enables real-time SQL analytics on your MongoDB or DynamoDB NoSQL database.

Rockset is the leading real-time analytics platform built for the cloud, delivering fast analytics on real-time data with surprising efficiency. Learn more at rockset.com.

--

--

--

Rockset, the Real-Time Analytics Platform Built for the Cloud, delivers fast analytics on real-time data with surprising efficiency.

Recommended from Medium

Debugging a Python Flask Application in a Container with Docker Compose

How to effectively manage Complex Code Bases

5 Things I Learned From My Dentist Wife That Apply to Engineering

Building My First App — JiffyCV

Containers and Virtual Machines: An Overview

Mobile Test Engineer: How to make an awesome bug report?

Bringing Salesforce’s “Pledge 1%” to Open Source

Elastic Beanstalk deployment made simple: end-to-end automation with CloudFormation and…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shawn Adams

Shawn Adams

Rockset

More from Medium

Your Startup Needs Microservices

wires connecting individual hardware components

Schrödinger’s Microservice

Modeling a service using the single table design in DynamoDB

Live Postgres database clone without downtime