-2

Background:

I'm trying to build the backend services of an app. This app has rooms where a user can join in to. When a user joins a room, s/he can exchange some data with other users through socket. Outside of the room, the user can view the processed data from the transactions that happened inside the rooms s/he joined in to. Room list, room informations, and the data transactions inside the room should be stored in a database.

My idea is to create a project with one database, however, an experienced developer suggested to the database into two:

  1. One that uses MongoDB for storing data transactions happening inside the room.
  2. One that uses MySQL for storing and returning room list, room information and analytics of what happened inside a room.

Problem I see with using multiple database:

I did some research and from what I understand, multiple database is not recommended but could be implemented if data are unrelated. Displaying analytics will need to process data transactions that happened inside a room and also display the room's information. If I use the two database approach, I will need to retrieve data from both database in order to achieve this.

Question:

I personally think it's easier to use a single database approach since I don't see the data inside and outside of the room as 'unrelated'. Am I missing an important point on when to use multiple database?

Thanks in advance. Have a good day.

asdf04
  • 9
  • 2
  • 3
    Why won't you use one database? It's advisable to use the least amount of moving parts in an app. – Ivan Mar 19 '18 at 22:26
  • I actually wants to use one database but also wants to hear other's opinion on this. My friend is more experienced than I am so I don't want to reject his idea without making an effort to understand it. – asdf04 Mar 19 '18 at 22:31
  • 2
    Your friend is trying to solve a problem that probably doesn't exist. Built it using one database and if there is a need later on for a 2nd DB technology then go for it. Don't obsess over it. Having 2 DB technologies from the get-go is gonna slow and overly complicate the development of an app you haven't even built yet. Over engineering is for suckers. – nicholaswmin Mar 19 '18 at 22:49
  • Time to read a textbook on intro to database management. Dozens are free online in pdf & there are also free academic slides & courses. PS Plus this is a duplicate question. Also off topic, too broad. Nevertheless a faq because people don't put effort into (re)searching. (See the downvote arrow mouseover text & [ask] & other links at the [help].) – philipxy Mar 20 '18 at 02:07
  • @philipxy edited my post. sorry for the confusion. And yes, I'm trying to read more about DBMS now while waiting for more advice I could get here. Thank you for your suggestion :) – asdf04 Mar 20 '18 at 02:10
  • Thanks for your advice sir. I tried describing my problem in more details now. I hope I have delivered the cause of my confusion well. – asdf04 Mar 20 '18 at 11:03

1 Answers1

3

You can look at this problem from two perspectives; technical and practical.

Technically, if your back-end is expected to become very complex or scaled, it is recommended to break it down into multiple microservices, each in charge of a tiny task. Ideally, these small services should help you achieve separation of concerns, so each service only works with one piece of the data. If other services need to read and/or modify that piece of data, they have to go through the service in charge.

In this case, depending on the data each service is dealing with, you can pick the proper database. For instance, if you have transactional data, you can use MySQL, MongoDB for large schemaless content, or Elasticsearch if you want to perform a text search.

Practically, it is recommended to start small with one service and database (if you prefer to develop your app sooner), and then, over time break it down into multiple services as you need to add and/or improve features.

There are multiple points to keep in mind. First, if you expect to have a large user base, you should start development with the right architecture from the beginning to avoid scaling issues. Second, sometimes one database cannot perform the task you need. For example, it would be very inefficient to do a text search in MySQL. Finally, there is no absolute right way of doing things. However you do one thing, another friend might show up tomorrow and ask you why you did not do it his/her way. The most important thing is to start doing and then, learning and improving along the way. Facebook was started with MySQL and it worked fine initially. Could it survive one database type today? I suspect the answer is no, but would it have made sense for them to add all the N databases that they have now back then?

Good luck developing!

Behrooz
  • 2,181
  • 1
  • 16
  • 24
  • I might take your advice to start with one and break it down to multiple as the app grows. Thanks for your kind answer and encouragement :) – asdf04 Mar 20 '18 at 11:08