avatarDr. Derek Austin 🥳

Summary

The article discusses three leading alternatives to MongoDB: JAM Stack, PostgreSQL, and Amazon's DynamoDB, each offering different advantages and disadvantages for developers considering a switch from MongoDB.

Abstract

The undefined website presents an in-depth analysis of the top three alternatives to MongoDB, a popular NoSQL database. The article begins by explaining the emergence of NoSQL databases in response to the scaling challenges faced by platforms like MySpace in 2009. It then delves into the reasons why some developers and companies, including The Guardian, are moving away from MongoDB, citing issues such as lost records, decreased performance, and the abandonment of traditional database features. The first alternative discussed is JAM Stack, which offers a serverless architecture with pre-built markup for fast, secure, and dynamic websites. The second alternative is PostgreSQL, a powerful and reliable SQL database known for its advanced features and performance. The third option is Amazon's DynamoDB, a NoSQL database service that provides scalability and integration with AWS services. The article weighs the pros and cons of each alternative, such as the ease of use and speed of JAM Stack, the robustness and community support of PostgreSQL, and the scalability and AWS ecosystem of DynamoDB. It also provides insights into the technical and operational considerations that influenced The Guardian's decision to migrate from MongoDB to PostgreSQL.

Opinions

  • JAM Stack is praised for its lightning-fast content delivery, maximum SEO, and minimal hosting costs, but it is not ideal for applications requiring frequent content updates or live data editing.
  • PostgreSQL is highly regarded for its continuous development over 30 years, platform independence, and superior performance compared to MySQL and MongoDB, though it introduces complexity due to its SQL nature.
  • DynamoDB is recognized for its seamless integration with AWS services, live migration capabilities from MongoDB, and the elimination of infrastructure management, but it is criticized for potential scalability issues and the complexity of managing throughput capacity.
  • The article suggests that JAM Stack is particularly suitable for static and infrequently updated sites, while SQL vs. NoSQL considerations will guide the choice between PostgreSQL and DynamoDB for more dynamic applications.
  • The author expresses a personal preference for JAM Stack, considering it a cutting-edge technology for static sites, and acknowledges the trade-offs between SQL and NoSQL solutions, emphasizing the importance of choosing the right tool for the job.
  • Some readers have pointed out additional disadvantages of DynamoDB, such as difficult indexing, lack of general query support, and

The Top Three Alternatives to MongoDB

JAM Stack, PostgreSQL, and Amazon’s DynamoDB are all competitive alternatives to MongoDB

Photo by Marlene Prusik on Unsplash

NoSQL is the name used to describe any type of database that does not correspond to the SQL relational model.

NoSQL databases originated in 2009 as sites like MySpace scaled up:

NoSQL came into existence because the databases at the time couldn’t handle the scale required.

— Rick Negrin on the memSQL Blog

MongoDB is the most famous of NoSQL databases. It is frequently used by JavaScript developers, especially those using MERN Stack or MEAN Stack (the combination of Mongo with Express, Angular or React, and Node).

Why People Are Leaving MongoDB

In general, NoSQL has significant differences from previous database architecture that can cause lost records and decreased performance:

NoSQL abandoned some of the core features of databases that make them highly performant and easy to use.

— Rick Negrin on the memSQL Blog

In response, many developers are considering moving away from MongoDB and NoSQL to alternatives such as JAM Stack, PostgreSQL, or DynamoDB.

The Guardian Famously Left MongoDB

The online publication and British newspaper The Guardian received over 100,000 views on its November 2018 article about leaving MongoDB:

In it, the developers who made the switch reveal that their team had problems with OpsManager — Mongo’s database management software — and that Mongo’s support agents were not much help during two outages.

I took a deep dive into the reasons the publication chose to move from MongoDB to PostgreSQL in Better Programming:

The Three Alternatives to MongoDB

While many people continue to use Mongo, there are many alternatives available for software developers and database engineers, such as:

  1. JAM Stack: Fast, secure, and dynamic web sites served without web servers.
  2. PostgreSQL: SQL database known for its reliability, features, and performance.
  3. DynamoDB: NoSQL database created by Amazon Web Services (AWS)

These three options are the current best alternatives to MongoDB. We’ll review the pros and cons of each choice in detail in the next section.

MongoDB Alternative #1: JAM Stack

JAM Stack is short for JavaScript, APIs, and prerendered Markup, and it is a type of serverless architecture that avoids needing a database at all.

JAM Stack could even replace a document database as long as the data could be moved to a whole lot of JSON files written in Markdown.

When using JAM Stack, the entire application is then compiled (or built), usually with a tool like Gatsby.

Unfortunately, that means that any change requires the site to be rebuilt.

On the other hand, dynamic content can change in real-time if it is accessed through an API, like comments handled through Disqus.

Advantages of JAM Stack

Lightning-fast content delivery is the biggest advantage of JAM Stack, because there is no server — the entire app is running client-side.

At the same time, there is also maximum SEO — because the app was pre-compiled, it is being served as static pages, not generated on-demand.

Another advantage to JAM Stack is minimal hosting costs. For example, static pages are basically free to host at AWS.

Disadvantages of JAM Stack

Every single change has to be re-built. That means the app needs to be recompiled before that change is going to be available live online.

And, the larger the website, the longer the build time. Every time.

Thus, JAM Stack is usually not seen as a good fit for apps requiring frequent publication, huge amounts of data, or live editing of data records.

MongoDB Alternative #2: PostgreSQL

Advocates of using SQL cite the ongoing prevalence of SQL architecture and superior ability to perform operation analytics on SQL databases:

[R]elational databases have evolved. They can can handle nearly all of the workloads, with the scalability, reliability, and availability requirements that modern applications demand.

— Rick Negrin on the memSQL Blog

In other words, if a SQL database can scale, then it is preferable to NoSQL.

PostgreSQL (also called Postgres) is a popular, free SQL database that calls itself “the world’s most advanced open source database” on its website.

Advantages of PostgreSQL

PostgreSQL is a powerful software that has been developed continuously for over 30 years. Lots of people use it and it has a vibrant community.

It is platform-independent. For those using AWS, it can be hosted using Amazon Aurora on the Amazon Relational Database Service (RDS).

Plus, PostgreSQL is blazing fast. Its performance is better than MySQL, and MySQL is already much faster than MongoDB.

Disadvantages of PostgreSQL

Using SQL inherently adds complexity to any project. It is an entirely new programming language for a team to use on a day-to-day basis.

It can be difficult to migrate from NoSQL to SQL. They are fundamentally a different type of database structure. NoSQL is a document store with key-value pairs, while SQL is composed of tables and rows.

One option, and what The Guardian used in their migration, is the JSONb column type in PostgreSQL. However, using JSON blobs feels kind of like a hack, like shoehorning a NoSQL database into a SQL format.

MongoDB Alternative #3: DynamoDB

DynamoDB is the NoSQL product from Amazon Web Services (AWS). Both MongoDB and DynamoDB store JSON-like data with arbitrary schema.

DynamoDB recently added a feature called encryption at rest, and now it is highly competitive with MongoDB while still being a NoSQL database.

That means migration from MongoDB to DynamoDB is really pretty easy.

Advantages of DynamoDB

DynamoDB is the flagship NoSQL database on AWS, so its inherent advantage is the AWS platform’s cost, speed, and reliability.

As an AWS product, it easily integrates with AWS Lambda and API Gateway.

The big advantage of DynamoDB for anyone currently using Mongo is that users can perform a live migration from MongoDB straight to DynamoDB.

The best part is there is no infrastructure to manage — Amazon handles it.

Disadvantages of DynamoDB

If I am of the opinion that NoSQL has too high of a probability of losing records, then DynamoDB is not going to be a good choice for me.

DynamoDB can have scalability problems, like those associated with so-called hotkeys, records that are assessed much more frequently than others.

In addition, compared to MongoDB, DynamoDB supports less complex data types and is an AWS-exclusive product.

DynamoDB is no MongoDB

Helpful readers like Samantha Atkins and Fredrik Erasmus took the time to respond to this article with other disadvantages of DynamoDB.

  • Indexing is difficult with DynamoDB, which has no general query support without full table scans.
  • DynamoDB makes it hard to retrieve even a simple count of documents from a collection, and it does not use cursors.
  • DynamoDB’s hotkeys and hot partitions require technical expertise in order to use effectively.
  • With DynamoDB on AWS, you have to specify “throughput capacity” in terms of RCUs (read capacity units) and WCUs (write capacity units), adding significant complexity to your project.

DynamoDB has been called “the most unfriendly persistence solution I have [ever] worked with.” Indeed, MongoDB’s own advertising copy lists a dozen advantages of MongoDB over DynamoDB.

So, definitely be sure to think twice before switching from MongoDB to DynamoDB, despite the apparent similarities between the two.

My Opinion

“Containers won the battle, but will lose the war to serverless.”

— Simon Wardley quoted in HackerNoon

JAM Stack is one of coolest technologies out today. It is absurdly fast, accessible, and SEO-friendly, plus static files are free to host on AWS.

However, JAM Stack is only the right option for apps that have the luxury of being able to have a build step and recompile every change.

If you ask me, I would argue that even very large websites could be built on a JAM Stack through scheduled compilations, say hourly. JAM Stack is rad.

It might not work for a news site, but many dynamic sites do not need content updated more frequently than that, and static sites surely do not.

SQL vs. NoSQL

If needing a compilation step is a deal-breaker for a project, then it comes down to SQL vs NoSQL: PostgreSQL or DynamoDB.

PostgreSQL does not have to be hosted on Amazon, though it can be hosted at Amazon RDS. DynamoDB was developed by and is exclusive to Amazon.

SQL databases are inherently more powerful but also more complicated. Their strength is in business analytics and search.

NoSQL databases are easier to set-up and sufficient for many projects. That’s why The Guardian considered DynamoDB for their 2.3m articles.

In the end, they chose PostgreSQL because DynamoDB did not offer encryption at rest back in 2017, but they may well have made a different decision if they were considering a move from MongoDB today.

Wrap-Up

JAM Stack (serverless architecture) is a wonderful option, especially for any site that is mostly static, and is also a great technology to be aware of.

PostgreSQL has a huge community and offers all the power of SQL in a reliable, feature-rich, open-source package with great performance.

DynamoDB is a drop-in replacement for MongoDB that gives you scale, security, and speed without needing to maintain any infrastructure.

Additional resources

  • The website PostgreSQL Tutorial teaches about what makes “PostgreSQL stand out from other database management systems”:
  • If you ask the people at Mongo, MongoDB is way better than DynamoDB:

Join my email list to get free access to all of my Medium articles.

Technology
Programming
JavaScript
Postgres
AWS
Recommended from ReadMedium