MongoDB vs MySQL: Which to choose for web projects?

The fight has always between the two – MongoDB and MySQL. And what one lacks, the other compensates, so you really get confused on whether to go for relational database or non-relational databases. The ultimate question however should be “What kind of web project are you going to do?” This would of course, lead to a plethora of other questions like:

  • What kind of data are you going to store in the database?
  • How scalable do you want your app to be?
  • What’s skill of your developers in terms of database?
  • Can the database handle more requests or more joins?
  • What’s the coding language or front-end framework that you are planning to develop your web app in?

MongoDB

Developed by 10gen, MongoDB is a popular open-source document-oriented database. The documents are created and stored in BSON files (Binary JSON or Javascript Object Notation) format. All kinds of JS formats are supported, so you will find this database used popularly in many Node.js projects. JSON makes it possible for the data transfer between servers and web apps, so it would be a good choice when the requirement is to have storage capacity and speed.

Major advantage of MongoDB – The use of dynamic schemas because you no longer need to predefine the structure (for example, fields and value types). This makes it easier to add or delete fields array storage so you can change the records structure. Hierarchical relationships representation and array storage is also possible.

Where would MongoDB be suitable?

Suppose, your project is to create a web app with a heavy write load… then MongoDB would be the best choose.

But… there are a situations where MongoDB wouldn’t be a good choice. Here are some of those situations:

  • If you have very important security-critical information to store in the application’s database, then you may not get the security level that you might need.
  • If you want to join tables to your database, then it would be a good choice.
  • The stability may not be what you expect if you are looking to use it as a primary database system.
  • If you need transaction support

MySQL

MySQL is a full-featured open-source relational database management system (RDBMS) built by MySQL AB. Presently owned by Oracle Corporation, the system stores data in tables. This is then grouped into databases and the access is done through Structured Query Language or SQL, with the commands “Select”, “Update”, “Insert” and “Delete”.

There are various tables, wherein you can store related information. But with the “Join” operation command, you can correlate the data and perform queries. There is little chance of data duplication.

Compatibility with different operating systems – Windows, Linux, Unix, Apple, FreeBSD to name a few. The system supports these storage engines as well – InnoDB (default), Blackhole, Federated, Memory, MyISAM, CSV, Archive, and Merge.

The key features of MySQL are:

  • Full-text searching & indexing’
  • Triggers
  • Query Caching
  • SSL support
  • Unicode support
  • Different storage engines with various performance characteristics
  • Triggers
  • SubSELECTs

Key features of MongoDB are:

  • Auto-sharding
  • Native replication
  • In-memory speed
  • Excellent query language support
  • Support of various storage engines
  • Embedded data models support

Websites with MySQL:

NASA, US Navy, Walmart, Uber, Bookingcom, Twitter, Facebook, Sony, Zappos

Websites with MongoDB:

Expedia, Bosch, BuzzFeed, Forbes, Foursquare, eBay, Gap, City of Chicago, Adobe, MetLife

You can leave out MySQL and choose the other option:

  • When you need horizontal scaling. This is because scaling is definitely not a strong point of the relational database.
  • It cannot handle huge data volumes, so don’t look up to it when you want to handle high transaction loads.
  • The relational database many not serve you well when it comes to implementation, even though it’s been upgraded with replication and clustering features.

Considering these limitations, you can think about using MySQL database as the backend for the following:

  • E-commerce
  • Online retailers
  • E-auctions
  • Automated online assistants

You better leave MongoDB, and look out for MySQL, when:

  • You need a strict hierarchy of relationships between the entities because it can store your data in conventional tables with rows.
  • Real-time analytics is important
  • If you need high data protection standards, especially if you are planning a live-auction app
  • If you need a fully-featured database management system
  • When you need transaction support, and high-level security for all the transactions
  • You need to build an app with complex transactions
  • You need a snap-in replacement for legacy solutions

Which database to choose?

There is actually no straightforward answer to this because you have to consider several factors before deciding which one to choose.

MongoDB is several people’s favourite because it is open, collaborative, has a simple philosophy, with a helpful community.

Many people find MySQL a little difficult to use post Oracle acquisition. However, many companies still opt to choose MySQL, even if the focus is on MariaDB development.

Which one to choose when you are looking for Speed?

The relational database lacks speed and may pose problems when there are huge data volumes. So companies looking for smaller databases may need to look for generic solutions.

MongoDB can easily manage large and unstructured amounts of data. The document oriented system comes with GNU AGPL v3.0/Commercial license. However, it is worth saying here that MongoDB attracts people with its simple and open philosophy. There is a collaborative and helpful community of users, unlike MySQL. MySQL, on the other hand, is licensed under GPL v2/Commercial licenses.

So the answer is you really have to look into your project requirements and future goals. If you are looking for a high performing solution, with management ease, flexibility and reliability in data protection then MySQL would be a good choice. It makes you solve the issue of proper data indexing.

When the data is unstructured and complex and if it is not possible to pre-define the schema then the open source document would be a better choice. It is also a good choice when you need to handle large volumes of data and store them as documents.

Interesting Articles:
Which Database is Better and Why to Choose?
MongoDB VS MySql

Picture Source: BENOIT/ Suki_ ::


Looking to Hire Software Developers?
Contact Us To Save Upto 50% Of Development Cost and Faster Delivery

The author: Reema Oamkumar is engaged as a thought leader at www.Software-Developer-India.com which is a part of the YUHIRO Group. YUHIRO is a German-Indian enterprise which provides programmers to IT companies, agencies and IT departments.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.