Lets say we have a microservice A and a B. B has its own database. However B has to be horizontally scaled, thus we end up having 3 instances of B. What happens to the database? Does it scale accordingly, does it stays the same (centralized) database for the 3 B instances, does it become a distributed database, what happens?
-
13 instances of B is still 1 logical service. So you only need one database. – tom redfern Nov 29 '16 at 09:26
-
@TomRedfern Thanks for your answer ;) Have you ever been in a situation where you also have to scale the database? If so how'd handle it? – nobitta Nov 29 '16 at 13:16
-
possible duplicate of http://stackoverflow.com/questions/33399988 – KGhatak Apr 13 '17 at 19:30
3 Answers
The answer is based on the which kind of data should be shared from 3 B instances. Some occasions:
The B is just read data without write anything, the DB can use replicate methodology, and three B instance just read data from different DB instance, and DB was replicated.
The B instance can read/write data without interrupt other B instance, that mean every B instance can have designated data, and no data sharing between instances, the database was changed to three databases with same schema but totally different data;
The B instances should share the most of data, and every instance can occasion write the data back to the DB. So B instance should use one DB and some DB lock to avoid conflict between the instances.
In other some different situation, there will be many other approaches to solve the issue such as using memory DB like redis, queue service like rabbitMQ for B instance.

- 226,338
- 43
- 373
- 367

- 106
- 1
- 3
using one database by mutliple service instances is ok when you are using data partitioning.

- 158
- 1
- 5
As explained by Chris Richardson in pattern database per service,
Instances of the same service should share the same database

- 4,399
- 4
- 38
- 47
-
Sorry, but from where in this article you get exact that? I don't see any specific regarding data base when scaling microservice. – Kristoff Mar 20 '20 at 12:12