In this case, I suggest creating an aggregator service or backends-for-frontend.
This service will fetch data from both the services and aggregates it for your frontend(or for your client).
In this way, your order service doesn't need to depend on customer service for just getting a name or your client doesn't need to make another call for fetching data and do aggregation.
With BFF,
- You can add an API tailored to the needs of each client, removing a lot of the bloat caused by keeping it all in one place.
- Frontend requirements will be separated from the backend concerns. This is easier for maintenance.
- The client application will know less about your APIs’ structure, which will make it more resilient to changes in those APIs.
However, all these microservices patterns came with some tradeoffs and no exceptions for BFFs.
so Always keep in mind that,
- BFF is a translation/aggregation layer between the client and the services. When data is returned from a service API, the purpose of it is to aggregate and transform it into the data type specified by the client application.
- Avoid over-dependence on BFF and don't add application logics in this layer. As I said in the previous step it's just a translator.
- Implement a resilient design and timeout since this aggregator is calling other services and getting data. If one or more service calls take too long, it should timeout and return a partial set of data. Consider how your application will handle this scenario
- Monitoring of your aggregator and it's child service calls. Implement distributed tracing using correlation IDs to track each call.