Microservices: database and microservice instances

Suppose we have a microservice A and B. B has its own database. However, B must be scaled horizontally, so we get 3 instances of B. What happens to the database? Does this fit the scale, does it remain the same (centralized) database for 3 B instances, does it become a distributed database, what happens?

+5
source share
3 answers

using a single database with instances of mutliple service is good when you use data sharing.

+3
source

The answer is based on what data type should be shared with 3 instances of B. Some cases:

  • B is just the data read, without writing anything, the database can use the replication methodology, and three instances of B have just read the data from another instance of the database, and the database has been replicated.

  • Instance B can read / write data without interrupting another instance of B, which means that each instance of B can have assigned data and not use data exchange between instances, the database has been changed to three databases with the same design, but completely different data;

  • In instances of B, most data should be used, and each instance can write data back to the database. Thus, instance B must use one database and some database lock to avoid conflict between the instances.

In another different situation, there will be many other approaches to solving the problem, such as using a memory database, such as redis, a queue service, such as rabbitMQ for instance B.

0
source

As Chris Richardson explained in the template database for the service ,

Instances of the same service must share the same database

0
source

Source: https://habr.com/ru/post/1260485/


All Articles