Search code examples
springarchitecturecloudmicroservicescoupling

Microservice Coupling


I'm building a new application with microservice concepts, but I don't know how to communicate with another microservice without coupling. Here is my scenario.

I want to show a graphic bar about my sales but I have two microservices, the first one is the sales-service and the another one product-service. In this case I have to select the period I want to filter and then select the sales and after select the products from these sales, but I'm calling the product-service directly with REST and if my product-service going down fails every thing. What is the correct way to work in this scenario?

EDIT

Diagram of Architecture

This is the architecture with some services. The problem is that sale-service has to communicate with others services to get some informations.

We have a sales software in hundreds of client and this application recieves this data and we have a front-end that shows this informations. In this scenario, microservice is the best approatch?

I'm using Spring Cloud.


Solution

  • The obvious answer if you don't know how to communicate without coupling is not to communicate then.

    I really mean that. You should design your services in a way that does not require synchronous communication with other services to fulfill a business case. Doing otherwise, as you noted, leads to runtime coupling.

    Obviously if you have a "product-service", that already suggests this is something pretty much every other service will need. You baked coupling into the architecture by cutting it up in a specific way.

    Specifically in this case: the "sales" service should have all the data for the report, so it does not have to communicate. You might find that this data is actually not needed elsewhere, so there would be no real duplication of data.

    Have a look at these guys: http://scs-architecture.org/. They have a lot of good ideas how (and why) to avoid such couplings, and how to design independent services, or at least only "offline" dependent ones.

    Obviously this is not for everything. Most notably Netflix is doing coupling and "synchronous" calls, that's why they have all the cool frameworks for these sorts of things. But they also have a specific use-case, which might not be the same as yours.