With so many database technologies to choose from, selecting the right database for your business can lead to analysis paralysis.
Should you go with a NoSQL database like MongoDB, Apache Cassandra, ElasticSearch, Amazon DynamoDB? Or should you go with a SQL database like MySQL, Oracle, Microsoft SQL Server, MariaDB, Amazon Aurora, Google Cloud SQL, or Google Cloud Spanner?
Even further, should you go with more than one database to create the ideal database architecture for your business case?
Choosing the right database platform from the start is important because migrating your data in the future can become a headache. It’s helpful to look into each popular database technology and understand how it relates to other databases in architecture, its pros and cons, and recommended use cases.
Here we take a look at MongoDB, a popular NoSQL database.
What is MongoDB?
MongoDB is a document database known for its remarkable scalability and flexibility.
At a glance, MongoDB:
- is open-source and cross-platform
- is non-relational, or NoSQL
- Is a distributed database for high availability, horizontal scaling, and geographic distribution
- stores data as “documents” rather than fixed tables
- stores data in BSON, a Binary JSON format
- is designed for high-volume data storage
- can process large amounts of real-time data very quickly
- is designed to be simple and fast for developers
- makes it easy to query and analyse data
- promises to protect data integrity and meet security and compliance standards for mission-critical workloads
MongoDB is a popular choice and, according to Stackshare, is used by more than 4,300 companies, including Toyota, Uber, Lyft, Accenture, Coinbase, Bosch, Expedia, Forbes, Urban Outfitters—you name it.
Is MongoDB a NoSQL Database? What’s the difference between SQL and NoSQL?
MongoDB is a NoSQL database and has existed since 2007. Let’s look at what that means.
SQL stands for Structured Query Language. SQL databases are the more traditional category and were first developed in the 1970s. They were designed to reduce data duplication because storage was expensive and it was more cost-effective to just hire engineering expertise to plan, build, manage, and manipulate databases as needed.
SQL databases are also called relational databases because they’re designed to organise data in predefined relationships using tables of columns and rows. As a Google cloud article explains, they’re “often used for a well-structured data model or for transactional queries in which the data structure does not change often.” The Structured Query Language is basically how you communicate with the database. It’s what you use to perform all the various tasks associated with relational databases, such as extracting, organising, and manipulating data.
In contrast, NoSQL databases store data in formats that are different from SQL databases. NoSQL databases entered the scene in the late 2000s when (1) storage costs (and thus, data duplication) became less of a concern, (2) data started becoming too varied and complex to force into predefined schemas, (3) engineers needed to be able to keep up with fast-changing requirements, (4) companies needed to make resilient applications that could be distributed and scaled out, and (5) the need to query data quickly and intuitively became a priority.
Why do Businesses choose a NoSQL database?
Businesses will often go with a NoSQL database like MongoDB when they:
- operate in fast Agile environments
- need to store both structured and semi-structured data
- process very large volumes of data
- anticipate having to scale out
- run a lot of microservices as part of their applications
But before you think that SQL and NoSQL databases are mutually exclusive, please note that in some business cases, it might make sense to integrate MongoDB with an existing relational database.
In fact, enterprises will sometimes use a NoSQL database in conjunction with a more traditional relational database when they have multiple departments—with varying skill sets—accessing the data for a variety of business purposes. For this reason, as a Redgate Hub article by Jackie Barre explains, “NoSQL databases like MongoDB can therefore benefit from successful coexistence with relational databases.”
Does MongoDB support transactions? And does it support ACID transactions?
The MongoDB documentation itself confirms that this database does indeed support transactions, including “multi-document transactions.”
You see, a common misconception is that NoSQL databases—by definition—cannot support something called ACID transactions, but that’s not the case … at least not across the board. In 2018, MongoDB began supporting ACID transactions in multi-document events and, in 2019, extended it to distributed multi-document ACID transactions in version 4.2.
ACID stands for atomicity, consistency, isolation, and durability. It’s a type of guarantee. It makes sure that there are no discrepancies in the database when transactions affecting multiple records take place (e.g., money withdrawn in one account = money deposited in another). In other words, even when a transactional error occurs, the database itself remains in a valid state.
For a long time, the concern was that the distributed-document nature of MongoDB, like many other NoSQL databases, would not be able to support ACID-like features. However, for the relatively small percentage of transactions you might need to perform in a non-relational database, MongoDB provides the capability where needed! MongoDB answers all of these questions on their “ACID Transactions” web page.
What are the advantages of MongoDB?
You’re choosing a mature, well-known platform: MongoDB entered the scene in 2007 and has enjoyed wide adoption across many industries. This has resulted in comprehensive documentation and a robust support community.
“Out of the box” scaling: Using a method called “sharding,” MongoDB distributes data horizontally across multiple servers. And because data doesn’t live on a single server, you don’t have a single point of failure, so there’s rarely ever a need for downtime. Being a distributed system, MongoDB is by definition partition-tolerant. It keeps working even in the event of a network or node failure.
Strong consistency: MongoDB’s architecture scores high for consistency, which basically means that every client sees the same data.
Tunable to meet availability requirements: In general, people think that when you choose a NoSQL database (which, by definition, has high partition tolerance), you have to either compromise on consistency or availability. This is based on the CAP Theorem or PACELC Theorem. But you don’t really have to compromise with MongoDB; you can “tune” levels of consistency and availability to meet your requirements.
Pool large amounts of diverse data: MongoDB is great when you’re “bringing together tens or hundreds of data sources.” It gives you the tools you need to “create a single unified view” in ways that are superior to other databases.
Resilient repository: With multiple generations of documents, variations in data are inevitable. MongoDB can handle these inconsistencies. This reduces the need to redesign the repository as things change.
Works with hybrid and multi-cloud applications: MongoDB supports pretty well any configuration we see in the world today and can be adapted to different use cases as they evolve. It doesn’t hurt that MongoDB is very developer-friendly. Building faster helps you go to market faster.
With that in mind, let’s talk about MongoDB’s three main offerings and their pricing: MongoDB Community Edition, MongoDB Atlas, and MongoDB Enterprise Advanced.
MongoDB Community Edition vs MongoDB Atlas vs MongoDB Enterprise Advanced
MongoDB consists of various versions, let’s take a look at the differences between some of them :
What is MongoDB Community Edition?
The Community Edition is the free-licence, open-source version of MongoDB. It’s a great choice for getting started with smaller or even medium-sized applications. You can install it on Linux, macOS, or Windows.
What is MongoDB Atlas?
MongoDB Atlas is the cloud-hosted Database-as-a-service (DBaaS) offering of MongoDB. As the fully managed option, MongoDB Atlas takes server management, network infrastructure, and configuration off your plate.
Getting started with MongoDB Atlas is free in their Shared tier, for a shared cluster with up to 512MB of storage. This is MongoDB Atlas’s “free forever” plan, and it can easily be upgraded to the pay-as-you-go dedicated-cluster tier, which can handle more sophisticated workload requirements. Pricing for the Dedicated version is billed monthly at various price points per hour, depending on usage.
But there’s also a third option—the Serverless tier—suitable for applications “with variable or infrequent traffic.” It’s priced at $0.10 per million reads, with up to 1 TB of storage.
Does MongoDB Atlas integrate with major cloud platforms?
Yes, MongoDB Atlas works with AWS, Azure, and Google Cloud. It allows you to run your database on multiple clouds using the same service. It’s “the only globally distributed, multi-cloud database.” You can deploy a single database cluster across multiple clouds and across 70+ regions.
What is MongoDB Enterprise?
MongoDB Enterprise allows you to run MongoDB on-premise or in a private cloud with enterprise-grade technical support and compliance needs.
What are some use case examples?
MongoDB’s inherent flexibility makes it appropriate for a vast variety of use cases—sky’s the limit.
MongoDB is great for businesses that foresee a continuous rather than temporary need to scale and want to be able to support sudden jumps in traffic. Basically, you can scale without having to invest a fortune in engineering and hardware.
More and more companies are building new applications that turn big data into competitive advantages. Companies everywhere are now looking to leverage real-time analytics to create better, more personalised customer experiences. So anywhere you see analytics potential or a move to Internet of Things (IoT), MongoDB can play a pivotal role.
Industries include and are definitely not limited to:
- Finance: modernising payments, easier scaling, faster transactions, microservices, data modelling
- E-commerce: content management, asset management, dynamic queries, personalisation, scale-on-demand ability to handle seasonal peaks in demand
- Marketing: content management, tracking, analytics
- Media and publishing: content management, delivery, user data management, and digital asset management
- Aerospace and Aviation: real-time decision-making based on weather (e.g., NASA’s Flight Awareness Collaboration Tool “FACT”)
- Travel: reservation and booking systems
- Genetic research: ability to deal with unstructured data and provide huge computing power
- Pharmaceutical: data modelling, accelerated R&D
- Demographic studies: ability to handle big data
- Meteorology: live analytics and predictions based on weather data being collected—The Weather Channel uses MongoDB!
- Online video gaming: ability to instantly scale for online gaming, managing player profiles and leaderboards
Let’s look at what just a few prominent enterprise-level companies have done:
- Bosch used MongoDB to deliver “IoT-powered apps to its consumers.”
- Urban Outfitters used MongoDB to develop a content management platform and deliver a user-centric e-commerce app.
- Forbes also switched to MongoDB to design a faster, more reliable content management platform. In fact, MongoDB says that “among the Fortune 500 and Global 500, MongoDB customers include 10 of the top media and entertainment companies.”
- Expedia turned to MongoDB to design “Scratchpad,” which they used to deliver a more personalised and convenient trip planning experience.
- Amadeus—the travel reservation system used by over 124+ airlines in 190+ countries uses MongoDB “to keep the world moving.”
- Salesforce Marketing Cloud chose MongoDB for being easy to use and for being nimble, scalable, and so well-supported. MongoDB “powers 100% of Salesforce Marketing Cloud’s analytics solution.” It has enabled Salesforce Marketing Cloud to track and ingest “an average of more than 30 million events per day … into a single stream that’s easy to view, flag, and moderate.”
- AstraZeneca Pharmaceuticals relies on MongoDB for its ability to handle astronomical amounts of data needed for genomic sequencing and faster R&D.
The use cases are now countless and downright fascinating.
For any company that’s planning to use analytics for a competitive edge, constantly improving user experience, offers mobile applications, and needs to be able to scale on demand, MongoDB is a great choice.
How can I learn more?
This article is part of a greater series centred around the technologies and themes found within the first edition of the Devoteam TechRadar. To read further into these topics, please download the TechRadar.
Want to know more about MongoDB?
Check out our TechRadar to see what our experts say about its viability in the market.