Karl Robinson
May 4, 2020
Karl is CEO and Co-Founder of Logicata – he’s an AWS Community Builder in the Cloud Operations category, and AWS Certified to Solutions Architect Professional level. Knowledgeable, informal, and approachable, Karl has founded, grown, and sold internet and cloud-hosting companies.
In this post we explore two giants of the NoSQL Database world: DynamoDB from Amazon Web Services (AWS) and MongoDB.
We’ll start by taking a look at what NoSQL actually means and then examine the two different offerings, looking at the pros and cons of both. Each of them has their advantages and disadvantages—your choice is likely to be guided by your long-term cloud strategy and the specific requirements of your application.
First up, what exactly is NoSQL?
What is a NoSQL Database?
You can find a full description on Wikipedia, but let me summarize here. A NoSQL database is a mechanism for storing data that is not structured in the same tabular format as a relational database. NoSQL databases are often used in big data and real-time web applications.
The advantages of NoSQL over relational databases include:
- Easier horizontal scaling to clusters of servers
- Simplicity of design
- Better availability
- Data structures are more flexible and make some operations faster
These are the most common data structures used by NoSQL databases:
- Key-Value Store: data is represented as a collection of key-value pairs—an attribute name and a value e.g <department, sales> or <company name, logicata>.
- Wide Column: uses tables, rows and columns like in a relational database, but unlike a relational database, the names and formats of the columns can vary from row to row in the same table. A wide column store can be interpreted as a two-dimensional key-value store.
- Graph: focuses on the relationships between data. A graph is composed of two elements—a node and a relationship. A node represents an entity and a relationship represents how two nodes are associated. For example, two nodes ‘mammal’ and ‘whale’ would have the relationship ‘is a type of’ pointing from ‘whale’ to ‘mammal’. In the graph world these relationships are more important than the individual nodes or data points.
- Document: data is encapsulated in a ‘document’, which is a standard format or encoding e.g. XML, YAML or JSON. Each document has a unique ‘key’ to identify it. Documents can be grouped using collections, tags, metadata or directory hierarchies. Collections are similar to tables on a relation database, while documents are similar to records. But, they differ in that every record in a relational database has the same sequence of fields, whereas documents in a collection can have an array of different fields.
No SQL databases generally compromise consistency of writes/reads with availability and speed. Ever uploaded a photo to social media only to find you can’t view it for a while? It’s more than likely due to the inability to read data that has not yet been synchronized across all database nodes. Barriers to NoSQL adoption include:
- Use of low level query languages
- Lack of standardized interfaces
- Large enterprise investment in existing relational databases
What is AWS DynamoDB?
AWS DynamoDB is a fully managed proprietary key-value and document NoSQL database that can deliver single digit millisecond performance at any scale. DynamoDB includes security, backup and restore, and in-memory caching. It is a multi-region and multi-master database deployment, which can scale to handle tens of millions of requests per second.
DynamoDB was launched in January 2012.
Applications include mobile, web, gaming, ad tech, retail and IoT. Common use cases vary by industry, but include:
- Metadata stores
- User detail stores
- User transactions
- Inventory tracking and fulfilment
- Game states
- Shopping carts
The main benefits of AWS DynamoDB are:
- Low latency: single digit millisecond data access at any scale, anywhere in the world
- Serverless: no servers or database software for customers to provision, install and manage
- Autoscaling: scales up and down to handle load spikes
- Security: all data encrypted by default; granular identity and access control on all tables
Pricing Models
There are two AWS pricing models for DynamoDB—users are charged for reading, writing and storing data in Dynamo DB tables.
On-demand Capacity Mode: users don’t need to specify how much read and write throughput they expect from their application as DynamoDB instantly scales up or down to accommodate workloads. This pricing model works best for unpredictable application traffic, but ultimately may be more expensive.
Provisioned Capacity Mode: users specify the number of reads and writes per second that their application will require. This pricing model works best for predictable or consistent application traffic and may work out more cost-effective for users who are able to accurately forecast demand.
AWS Dynamo DB is available on the AWS Free Tier, meaning users can experiment with building their first DynamoDB tables at no cost.
Migration
Amazon offers migration guides to migrate to DynamoDB from other database engines, including MongoDB, Cassandra and MySQL. Plus, they offer the Amazon Database Migration Service tool to simplify migrating to DynamoDB.
What is MongoDB?
MongoDB is a scalable, flexible document database written in C++ that is easy for developers to use, yet still provides all the functionality required to meet complex and high performance requirements at scale. MongoDB is developed by MongoDB Inc, a US-based software company.
MongoDB stores data in JSON-like documents. Fields can vary in different documents and data structure can also change over time.
MongoDB was launched in February 2009.
MongoDB provides a number of powerful ways to analyze data, including:
- Ad hoc queries
- Indexing
- Real-time aggregation
MongoDB is designed from the ground up to be a distributed database, which means that high availability, horizontal scaling and multi-region distribution all come as standard and are easy to set up.
Pricing Models
MongoDB is free to use and includes:
- End-to-end security
- Management tools for automation, monitoring and backup
- Compass for schema exploration and native document validation
MongoDB also has a paid offering (priced on application). MongoDB Enterprise Advanced includes additional features, such as:
- Proactive support
- Ops manager
- Kubernetes integration
- Advanced security
- Advanced analytics and visualization
- On-demand training
MongoDB can be run on customer-managed servers or with MongoDB Atlas on AWS, Azure and GCP. MongoDB is therefore cloud agnostic, with no vendor lock in. MongoDB describes Atlas as the ‘easiest way to run MongoDB’.
Migration
If you want to run MongoDB in Atlas in the public cloud, you can use the Atlas Live Migration Service. You can migrate data from an existing environment from any location including:
- AWS
- Azure
- GCP
- On-premises datacenter
- Third party database as a service provider
Atlas Live Migration Service is offered free of charge and is a hosted, fully managed service. Atlas Live Migration Service makes an initial copy of your source database and then keeps any changes synchronized until you are ready to make the cut over. While syncing, your application can still continue to read from and write to the source database. Once you are ready to make the switch, you simply need to update the connection string in your application code to point to the new MongoDB Atlas database.
AWS DynamoDB vs MongoDB
So, now we know what NoSQL is and what both AWS DynamoDB and MongoDB are. Let’s take a look at some of the key differences between these two NoSQL database offerings.
Database Location
MongoDB can be hosted anywhere—any public or private cloud or on-premises datacenter.
AWS DynamoDB is a fully managed AWS service, so you can obviously only run it in the AWS cloud—there is no on-premises option.
Setup and Installation
MongoDB is difficult to install and configure and there is little support available to assist with this. Therefore, specialist skills are required, which are a potentially expensive resource. MongoDB Atlas goes some way towards solving this problem if you are happy to host your MongoDB in the public cloud.
AWS DynamoDB is simple to set up, as it is a fully managed AWS service that can be configured via the AWS console or the AWS API.
Database Performance
Some of the main features that determine the performance of MongoDB include:
- Automated sharding, horizontal scaling and optimum data location to ensure low latency database writes from any geographic region
- HA clusters enable 99.995% uptime Service Level Agreement (SLA) regardless of where MongoDB is hosted
- JSON-formatted documents increase speed and flexibility
- Complex queries executed within MongoDB, minimizing the requirement for third party data analytics tools
- Rich monitoring and real-time performance dashboards give great visibility into database performance
Underpinning the performance of DynamoDB you’ll find:
- Automatic replication of database tables across AWS regions, enabling globally distributed applications to access data locally to ensure single digit millisecond latency
- Autoscaling of database tables, throughput and storage for performance and capacity as database traffic grows and shrinks
- Five 9s monthly uptime Service Level Agreement (SLA) per AWS region
- Managed in-memory caching enables microsecond read times and supports peaks of 20+ million requests per second
- Huge volumes of data backed up with no impact on database performance
Database Queries
AWS DynamoDB supports key-value queries. In order to perform analytics queries, data must be replicated to another AWS service such as Amazon Athena.
MongoDB has a rich query language—queries can be performed by single keys, ranges, faceted search, JOINs and graph traversals, as well as geospatial queries. Fast analytics queries can be achieved with on-demand materialized views.
Database Security
Like many AWS services, AWS DynamoDB is very secure by default. DynamoDB can only be accessed via the AWS SDK and access is secured by AWS IAM (Identity and Access Management). Users of AWS DynamoDB simply need to follow standard programming best practice, the rest is taken care of by AWS under their role in the ‘Shared Responsibility Model’ for security. Data is encrypted at rest by default in DynamoDB.
MongoDB offers RBAC (Role-Based Access Control), which includes standard, well defined roles and the ability to create custom roles. MongoDB supports SSL and TLS encryption and can pass through disk encryption. Beware though, that unless you’re using MongoDB Atlas, you’ll be responsible for the security of the entire stack on which MongoDB is hosted.
Programming Languages Supported
You’ll see from the table below that MongoDB supports many more programming languages than AWS DynamoDB. So, if you need a NoSQL database to be compatible with a specific language then you may find yourself forced to choose one option over the other.
Programming Language | MongoDB | AWS DynamoDB |
---|---|---|
.NET | No | Yes |
Actionscript | Yes | No |
C | Yes | No |
C# | Yes | No |
C++ | Yes | No |
Clojure | Yes | No |
ColdFusion | Yes | No |
D | Yes | No |
Dart | Yes | No |
Delphi | Yes | No |
Erlang | Yes | No |
Go | Yes | No |
Groovy | Yes | No |
Haskell | Yes | No |
Java | Yes | Yes |
Javascript | Yes | Yes |
Lisp | Yes | No |
Lua | Yes | No |
MatLab | Yes | No |
Node.js | Yes | Yes |
Perl | Yes | No |
PHP | Yes | Yes |
Powershell | Yes | No |
Prolog | Yes | No |
Python | Yes | Yes |
R | Yes | No |
Ruby | Yes | No |
Scala | Yes | No |
Smalltalk | Yes | No |
Swift | Yes | Yes |
Which Database is Right for Your Business?
As I mentioned at the beginning of the article, the answer to this question is not necessarily an easy one. It will depend largely on the long-term cloud strategy of your business, as well as the specific requirements of your application.
Both of these NoSQL databases can deliver performance and high availability at global scale.
If you are all in on AWS, then DynamoDB is the obvious choice of NoSQL database. But, if you’re already heavily invested in an on-premises data centre or another public cloud (e.g. GCP), it may not make sense for you to host your NoSQL data in AWS.
If you have a multi-cloud strategy, then MongoDB may be the way to go, as it is capable of running in any cloud.
If you want some advice on the best direction to go with your NoSQL database requirements, get in touch with one of Logicata’s cloud experts. We’ll be happy to discuss your specific use case and advise on the best way forward. If you have high performance database requirements, then check out our AWS Managed Services, where we can help to build, monitor and manage a NoSQL database on AWS.