It's been a while now since I last posted. No, I did not die, I had just a big break to start my own company.
Should I go MongoDB or MySQL?
That's why I just did some research about MongoDB and MySQL. If you already know both, you would tell me: "Man, this is completely diffferent, you can't just benchmark this". I agree. One is schema-less, not-relational database (MongoDB), the other one (MySQL) is not.
People will tell you "it depends on your needs". But most of the times, it is not so simple. You may need both actually. One for your "Big Data" (god, I hate this word), one for your relational data.
For example, you have users and you have movies. Your movies should definitely go to MongoDB since you want your users to be able to look for your millions movies quickly. But you also want your users to have notifications, points and relations with other users in which case MySQL is more appropriate.
That's when you wonder if you should use only MySQL, only MongoDB or both of these databases. So I did a little research and here's what I found:
StackOverflow - Mysql vs Mongodb 1000 reads which was great because Sean Reilly did really well explain how they both work and how you can boost performance using one or another.
MoreDevs - MySQL vs MongoDB performance benchmark which was great because you can really see by yourself in which use case one is better than the other.
Is MongoDB always faster then MySQL? is great to go further. You will learn why MySQL and MongoDB are so different: most of it is related on how they are processing queries (and all the lock mechanism). You will also learn about the importance of using indexes in MongoDB.
Before jumping to the conclusion, I will also talk about ORMs since I checked that up a little bit. First of all, ORM (Object-Relational Mapper) such as Doctrine (PHP), Hibernate (Java) or EntityFramework (.NET) are to SQL Databases (MySQL, PostgreSQL, Oracle, ...) what ODM (Object Document Mapper) such as DoctrineMongo (PHP), Mandango (PHP) are to NOSQL Databases (MongoDB, Cassandra, ...).
This layer of abstraction helps the developer by building itself queries to the database and instantiate objects after fetching data in the database. It's a really big time-saver and it's great for flexibility and future maintenance.
My dear friend Mathieu Pheulpin who has worked with both Doctrine (ORM) and DoctrineMango (ODM) explained to me that they are both great tools but you should always consider using it... or not.
If you are looking for highest performance, not using it is the best way to go since you will be able to query the database exactly the way you want.
On the other hand, if you are looking for flexibility, maintenance and simpler code, you should definitely give a hand to ORM/ODM.
Since my performance key is on retreiving movies, I will use an ORM for my users and no ODM for my movies. I will tell you in some future if my choice was wise or not.
To conclude this post, as you read, the choice between MongoDB vs MySQL (and moreover NOSQL vs SQL) is not so simple. In real world, you often need both. The best way to go with this is to check your needs.
Do you need big "JOIN"s? In which case, this data might be better in a SQL DB.
Do you often need to process a large amount of data? In which case, this data might be better in NOSQL DB.
Once you checked this, you might be able to know if you need both of them and what part of your data will go in one or another.