Should Node.js and MongoDB be in different containers?

I am trying to host a simple Node.js application connected to MongoDB, I look online, I found 2 different methods and several tutorials for this:

  • Various containers:

    • Example from the official Kubernetes documentation.
    • An example from the official Google Cloud Platform documentation.
  • Same:

    • Example from official IBM documentation.

It confused me a little, what is the best way to do this?

+3


source to share


1 answer


You have to put them in different containers.

By being in different containers, you can increase the number of replicas of the web application part to as many instances as you need, and you will still have one MongoDB instance.



If you had them in the same container, you would not be able to scale to multiple instances, since each replica would have its own MongoDB instance and therefore separate data. If you are doing updates to data in MongoDB from a web application, it will cause all sorts of problems, as subsequent requests can suffer from the instance difference and therefore view different data.

+5


source







All Articles