In this post we explore 2 giants of the NoSQL Database world – DynamoDB from Amazon Web Services, and MongoDB.
We’ll take a look at what NoSQL actually means, then examine the 2 different offerings, looking at the pros & cons of each. Each of course 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 & 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, eg <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 2 dimensional key-value store.
- Graph – focuses on the relationships between data. A graph is composed of 2 elements – a node and a relationship. A node represents an entity, and a relationship represents how 2 nodes are associated. For example, 2 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, eg 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, and documents 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 & restore and in-memory caching. It is a multi region and multimaster database deployment which can scale to handle tens of millions of request 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 & 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.
AWS DynamoDB Pricing Models
AWS have 2 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 & 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 – user specify the number of reads & 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.
Migrating to AWS Dynamo DB
Amazon offer migration guides to migrate to DynamoDB from other database engines including MongoDB, Cassandra, MySQL, plus they offer the Amazon Database Migration Service tool to simplify migrating to Dynamo DB.
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. Mongo B 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 change over time.
Mongo DB was launched in February 2009.
Mongo DB provides a number of powerful ways to analyze data, including:
- Ad hoc queries
- 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.
Mongo DB Pricing Models
MongoDB is free to use, and includes:
- End to end security
- Management tools for automation, monitoring & backup
- Compass for schema exploration and native document validation
MongoDB also has a paid offering (priced on application) – MongoDB Enterprise Advanced, which 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 describe Atlas as the ‘easiest way to run MongoDB’.
Migrating to MongoDB
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:
- On Premises datacenter
- 3rd 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 synchronised 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.
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 & 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 which can be configured via the AWS console or the AWS API.
Some of the main features that determine the performance of MongoDB include:
- Automated sharding, horizontal scaling, optimum data location to ensure low latency database writes from any geographic region.
- HA clusters enable 99.995% uptime SLA regardless of where MongoDB is hosted.
- JSON formatted documents increase speed and flexibility.
- Complex queries executed within MongoDB, minimising 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
- 5 9’s monthly uptime 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.
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, and geospatial queries. Fast analytics queries can be achieved with on-demand materialized views.
AWS DynamoDB, like many AWS services, 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 practise, 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 it may be you are forced to choose one option over the other.
|Programming Language||MongoDB||AWS DynamoDB|
Amazon DynamoDB vs MongoDB – which one 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, plus 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 no SQL database. But if you’re already heavily invested in an on premises datacentre, or another public cloud such as AWS or GCP, it may not make sense for you to host your NoSQL data in AWS.
If you have a multicloud 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, talk to a Logicata cloud expert who will 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.