If microservice A needs to combine data from services B & C (that are not aware of one another), should B (or C) do the data merging for service A, or it will be up to service A?
So our retail website has a microservice that is responsible for
Get products by category, or do a
GET for a product ID and get info about the product's (image, price....).
The websites talks to this service to build all kind of "Product Lists" pages for the users - e.g. "Sports Products".
We have a new feature on the website -
Hot products, were the website will display a nice list of Hot Products for the user. Imagine a ticker with Hot Products on the checkout page.
So we have a new microservice that is responsible for the business logic of finding what are the relevant products for this specific user and return them to the caller (e.g. Hot products -> productIds: 456, 789).
The business logic of the
Hot Products service is less important. We can even imagine that for phase 1 it is:
if "morning" then products 123 & 456. If "noon" then products 789 & 3030... and for phase 10 it will be an AI algorithm.
On the website, we need to display more data about the product (name, image, price,....). This data is can be found in the
And here comes the question:
Who is responsible to translate the
Hot products's meager IDs recommendations into something that the Website can use?
Option 1 - The
Hot products microservice will also take care of that. Instead of returning only a list of IDs, it will also call the
Products service in order to bring all the data that is needed by the UI and return a much richer response to the caller.
Drawbacks of option 1 - involving the display/usage business logic of "what needs to be done with the hot products list" into the business logic of the
Hot Products microservice. If another caller needs different product information (e.g. brand) the
Hot products microservice needs to be changed or at least "know" about it
Option 2 - The
Hot products will keep on returning only the IDs of the products, and it is up to the caller's responsibility to do with the data whatever it needs - e.g. calling the
Products microservice to bring the data it needs about the different products.
Drawbacks of option 2 - more work on the caller side. No more "one-stop-shop" at the
Hot Products microservice.
So where do we draw the line of responsibility or "Domain Driven Development" in such a case?