0
votes

I have a question about microservice architecture

for example if i have two microservice "UserService" and "TaskService"

and i have the database for my systeme with two table "USER" and "TASK"

We know that one of the Microservices rules is that each Microservice has its own database

So I don't know how to distribute my database for this two microservices ?

  1. set for the database for the "UserService" microservice two tables "USER" and "TASK"

and set for the database for the "TaskService" microservice two tables also "USER" and "TASK"

or

  1. set for the database for the "UserService" microservice the table "USER"

and set for the database for the "TaskService" microservice the table "TASK" but the problem here is how to link the two tables "USER" and "TASK" because each one is in a different database

1

1 Answers

0
votes

The first question you have to ask yourself is if in this case you really need a microservice architecture. If as you say, the service has only two tables, and the two are closely related (so both will propably belongs to the same bounded context). The most probably answer is no.

Because this way you will add more complexity and latency to the system.

With this in mind, If you really need this architecture, because the real application is more complex and you have identified that this two services belong to different bounded contexts, I mean their functionality are not closely related, the way to solve this is that each microservice owns its own database with its own table.

So the user service will have its own table as well as task service. If there is a use case in user service that needs information of task service or viceversa. You can do a request from origin service to target service to retrieve this information or if you really need to decouple the two and/or you have performance requirements, then the solution could be to have a read only table with the other service information that you need and update it by subscribe to the changes of the table owner using kafka for example or another message broker