Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Which Database Should I Choose for My Web App: MySQL or MongoDB?

Parent Feed: 

Each one of the two popular databases “lures” you with its own set of tempting features that the other one lacks. Yet, you need to go beyond the old “relational vs NoSQL” debate to find the answer to your “Which database should I choose for my web app?” question.

Therefore, it's more than a generic MySQL vs MongoDB comparison that we'll attempt to make in this post. It's not a well-founded answer to a question like “Which is the best database to use for web applications?” that we'll try to give.

Instead, we'll try helping you discover which is THE one that best fits YOUR own web app's use case.
 

It All Comes Down to One Key Question: “What Type of Web App?”

And just like a snowball rolling down a slope, once you've asked yourself this crucial question, expect it to “unleash” other key ones, as well:

  • What type of data will you be storing in your database? Is it relational data (e.g. social network-specific data, where each user has lots of associated photos, comments, groups etc.) or is it documents or analytical information that your web app's database will be storing?
     
  • Would you “trade” data protection guarantee (let's say... losing some of the stored data every dozen thousand transactions?) for really high data insert rate?
     
  • Would you store it in a relational schema guaranteeing you clear relationships between entities or would you go for a more flexible data storage format instead? One enabling you to perfectly store dynamic, unique items?
     
  • Do you expect your web app to grow any bigger? How big? Are we talking about a “very large” data volume? And this is probably the second most important question to ask yourself after the “Which database should I use for my web app?”
     
  • How many queries do you expect it to perform (per minute, hour, day)?
     
  • And which is your skills level (or your development team's skills level) in using various databases?
     
  • Will your database need to be perfectly equipped to support further and further joins?
     
  • What coding language/front-end framework will you be developing your web app in?

And you must surely agree that this is a never-ending list. There are so many aspects relevant for your specific use case, for your specific web app that you should take the time to determine.

And to focus on those which weight heavily in your database selection process.
 

“Which Database Should I Choose for My Web App?” Go With MongoDB If...

… it's a web app carrying a heavy write load that you're planning to develop.

MongoDB database's biggest advantage over a MySQL one is its capability to accommodate really large data volumes. Take the comments section of high trafficked websites (The New York Times or Craigslist) for instance. Loads and loads of content is being “pumped in”, at high speed, and MongoDB's perfectly equipped to assimilate it all.

Note: it might excel in terms of performance, yet it trades transaction safety to achieve that kind of performance. So, make sure you go with MongoDB only if it's not sensitive data that your web app's database will be storing. MongoDB does require a high level of risk tolerance, you know.

And there are plenty of other reasons why MongoDB might be a suitable replacement for MySQL for storing data. You should back your web app with a MongoDB database if:

  1. ... it's a small, a start-up business that you own. On open source document-oriented database, which doesn't pigeonhole your data in a rigidly structured schema (it simply stores all the values that you're inserting as documents), which is flexible, easy to set up, to manage, to deploy and to scale, is perfect for your own specific web app's needs.
     
  2. . … you dream big. This NoSQL database is built to scale (horizontally), to auto-shard (and to replicate) your data as it gets heavier.
     
  3. . … your web app doesn't require a complex data model and you're good to go with a simpler one. One with no further joins requests and much easier to deploy.
     
  4. .... it's a prototyping scenario that you're planning to use it in.

And Now: When Not to Use MongoDB?

For if it's best-suited for certain scenarios involving backing web apps, it certainly is ill-suited for others.

Here are some of them:

  • if you're looking for an easy way to join tables to your database... MongoDB is not IT
     
  • if you're planning to use it as the primary database system for... 1k machines, let's assume. It's not that stable.
     
  • if it's security-critical information that you're planning to store in your web app's database (e.g. critical customer information). MongoDB doesn't guarantee you the same level of data protection as MySQL
     
  • if it's relational data that you'll be storing (so if there are clear relationships between your entities, e.g. users and reviews)
     
  • if you're counting on transaction support

A MySQL Database Might Better Suit Your Web App If...

… it's a commercial/end-user app that you're developing, which depends on a strict hierarchy of relationships between various entities.

In this case, you can't expect a MongoDB, piling up your data in collections of separate documents, to meet your needs. It's a relational database like MySQL, which stores your data in “conventional” tables, made of rows, that you should back your app with.

And if this doesn't really answer your “Which database should I choose for my web app?” question, here are a few other use cases that might get you thinking:

  • it's not just a traditional RDBMS (relational database management system) that would meet your data storage needs, but a full-featured one. Luckily, MySQL is that “full-feathered” relational database that you need. Over the years it's been upgraded with views, cursors, clustering, triggers, query stored procedures etc.
     
  • real-time analytics is crucial for you 
     
  • you're not willing to trade high data protection standards (let's assume, for instance, that it's a live auction app that you're developing, which will store and retrieve data of critical importance) for... high data insert rate
     
  • you need transaction support, security assurance for all the transactions carried out on your app 

Also, to give you one more helping hand with your decision-making process, here's a short list of web apps where a MySQL database would work best as a back-end:
 

  • e-auctions
  • automated online assistants
  • online retailers
  • e-commerce
  • real-time big data analytics
  • dynamic pricing
     

When Not to Use MySQL? Which Are Its Key Limitations?

It's precisely those scenarios where MongoDB “shines” that MySQL doesn't.

Therefore, here are some more clues to help you find the answer to your “Which database should I choose for my web app: MySQL or MongoDB?”:
 

  • scaling is definitely not it's trump card; it can't possibly rival a MongoDB database when it comes to horizontal scaling
  • it can't handle high transaction loads so well; from a performance point of view, MySQL isn't built to cope with really big data volumes 
  • although it's been upgraded with replication and clustering features, their implementation isn't precisely a... no brainer
     

So, which one's going to be? Will you use MongoDB as a backing storage for your web app or MySQL instead?

Author: 
RSS Tags: 
Original Post: