Search code examples
restmicroservicescommunicationtransfer

Transferring data between microservices


I am taking care of extraction of microservice out of a monolith written in Java with help of Spring Boot. We are planning to divide the whole monolith into a few smaller microservices.

I have to enable communication between the monolith and the new microservice as it needs entities from the new microservice (it has its own database) to perform certain actions. I thought of exposing REST endpoints but then I would have to duplicate entities.

Is it acceptable? If so, then REST controllers based in monolith which retrieve entities from microservice should be placed in the same layer as repositories? This solution would increase coupling which should be avoided, are there any other approaches?

I'll be grateful for any responses as well as articles which in your opinion may help here. Thank you in advance.


Solution

  • It totally depends on your Use-Case. There is no general solution and it is totally okay to maintain a repository where shared resources are placed.

    If you take Microservice very strict, it would maintain the entities on its own. When transmitting the data you will use an intermediate format like JSON or XML which doesn't care about the structure of the data. The Microservice lives in its own world and only adresses his use-case. If another service undergoes a change and the entities change the other service should not be affected by this change. Each Service should only have the data it needs everything else is not his concern.

    Therefore I would not use a central repository but as stated before there are Use-Cases where this is the way to go. Maybe some specific endpoints could help you by solving this issue.