There is a project written using NodeJS and MongoDB.

We want to run it on multiple servrerah. But there were questions on mongodb.

In case we use one base for all servers, we think there will be a load and the base will simply not hold requests from all servers.

If you use your database for each server, then how to distribute data between the rest?

In the case of replication, how to determine that the data on the slaves have already appeared and we can send the user to the replica?

What solutions can be applied here?

  • If you are given an exhaustive answer, mark it as accepted ^^ " - Suvitruf

1 answer 1

In case we use one base for all servers, we think there will be a load and the base will simply not hold requests from all servers.

The problem in 1 node is not in this case in general. Replicas, etc. came up with generally more in order to increase redundancy. It does not matter that your base keeps the load. If the server crashes, everything will break with you. The concept of replicas with an automatic follower was invented to handle such cases.

If you use your database for each server, then how to distribute data between the rest?

So-so solution. Handles synchronize data between these databases?

In the case of replication, how to determine that the data on the slaves have already appeared and we can send the user to the replica?

First you need to decide whether you really need additional nodes because of the load?

  1. Optimize baseline, use connection pools, etc.
  2. Take tests, see how it handles current loads.
  3. In any case, raise the extra. autoloader nodes.

As for "In the case of replication, how to determine that the data on the slaves have already appeared." I understand the question about the "dirty data"? Yet again:

  1. Is this data critical? If this is, for example, a service of some aggregated statistics, then perhaps you are not so important relevance and you are allowed a bit outdated data, then you can safely read from the replicas.
  2. If, nevertheless, data consistency is needed, then you can specify the so-called write concern. As far as I remember, if you have 3 nodes and you specify w = 3 , then the write request will report success only when the changes are registered to all replicas.