Ask a programmer whether you should use MongoDB vs PostgreSQL and you’re likely to open a can of worms. The core philosophies are very different, but loyal fans will argue that their favorite can be used for nearly every application. It is true that there’s a lot of functional overlap between the two databases. However, MongoDB and PostgreSQL have some specific differences that give them the edge in different areas.
MongoDB is a document database, meaning data is stored in cohesive documents that contain all the data about a particular topic. There doesn’t need to be a consistent relationship between the data. Because of this, MongoDB is an excellent choice for Big Data projects and social media applications dealing with large amounts of unstructured data (in short, anything that wouldn’t fit neatly into a table, like a blog post or a video). Use MongoDB for:
- Storing large volumes of unstructured data
- Fast, iterative development and prototyping
- Scalability on short notice
- Cheap to host, on production environment, third party service is recommended for hosting
- High performance, data is accessible and very fast compared to most common RDBMS database
- Easy installation
- Easy to start development
- Compatible with most of development frameworks and platforms
- Many IDEs where you can see the data and run queries
- Numerous hosting/cloud services
- Large community
- Good for solutions where you need to cache and share the data
PostgreSQL is an object-relational DBMS where data is stored in correlative tables. Although it’s a solid general use database, the focus on defining the relationships between data and enforcing standards makes it a popular choice for those who prioritize data integrity. Even MongoDB’s website credits PostgreSQL with being superior at “complex, multi-row transactions”. Use PostgreSQL for:
- Applications that are highly sensitive to data loss (Banking, accounting, etc)
- Enabling complex SQL queries
- Prioritizing stability over scalability
MongoDB vs PostgreSQL Infographic
Check out this infographic for a comparison between MongoDB vs PostgreSQL:
The Choice is Yours
It’s important to remember that no project exists in a vacuum; there are dozens of factors that may influence technology choice. A good software developer chooses the best tool for each situation, regardless of whether the project is a typical use case.
For example, you might expect that a tax and customs authority like the UK’s HM Revenue and Customs would use PostgreSQL. Tracking taxes seems to call for the rigid data integrity of an RDMS. There are over 65 million taxable subjects in the UK, however. HMRC badly needed the rapid development possible with MongoDB to get its tax planning and payment tools into the hands of the citizens as soon as possible. Using MongoDB, they were able to move from a glacial two releases per year to putting out 50 releases every week. The result was a 21% decrease in paper filings and wait times reduced by half.
A final word of caution: avoid choosing a DBMS based on outside factors like trends. It is neither easy nor cheap to switch later on if you don’t like how your database is performing. Data migration can cost 25-50% of original set-up costs (not including the potential risk of lost data) and take years to finish. Being open to recommendations from your software developer will save you the expense.
Unsure which database is right for your next app? Let the experts at Concepta help you decide!