K
K
Konstantin T2019-09-21 10:21:44
Service Oriented Architecture
Konstantin T, 2019-09-21 10:21:44

Is it worth sharing databases between microservices?

There are, for example, 10 microservices, logically, each microservice has its own database. But then a situation arises in which you need to get a record from the database according to certain criteria, and then we got into a puddle, all this data is in different databases in different services, and we have to aggregate them through layers, instead of the usual JOIN QUERY into the database, we have something are we doing it wrong or is it the cost of microservice architecture? Is it logical to bring all the databases into one and from different services to get information directly, and connect all services to one database?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
skrimafonolog, 2019-09-21
@RooTooZ

microservices are for horizontal scaling.
that is, when you increase the load - you increase the number of servers.
Well, now think about what will happen to your database when you have a lot of servers with microservices, say 1000, and there will be only one database?
there will be a plug, that is, the whole point of horizontal scaling is lost.
for microservices, it is advisable to use - its own database for each.
and as a single link between them - use MQ.
if this happens often, then you incorrectly beat on microservices.
they are not functionally isolated enough.

�
âš¡ Kotobotov âš¡, 2019-09-21
@angrySCV

> Is it logical to bring all the databases into one and from different services
, this is logical only when the functionality was not correctly decomposed and they just try to cut one service into different parts with a single base,
for different microservices this should not be logical.
for example, a restaurant in the "delivery of dishes" service and in the "dish design" service has a "client" both there and there, but the data of this client in both services is different.
in delivery, the "client" has a full name and address,
in the design of dishes for delivery in a restaurant, the client has neither an address nor a full name (just client number 1, for example), but there is, for example, a table number, etc.
for both of these microservices, the data sources are different.

I
Ivan Shumov, 2019-09-21
@inoise

If the problem is ONLY in obtaining and aggregating data, then:
1. You have not yet known all the pain)
2. this issue is solved by GraphQL , designed specifically for this
. And the databases must be separated. This is the essence

X
xmoonlight, 2019-09-21
@xmoonlight

The type of storage depends on the type and purpose of the data.
1. If the data for microservices is different (heterogeneous) - this is the "ring" topology + centralized API.
2. If they are the same, this is a star topology (that is, a regular centralized database).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question