Let's use https://github.com/dotnet-architecture/eShopOnContainers as an example. There are CatalogService
, BasketService
and there is ApiGateway
. In api gateway in BasketController
there is AddItemToBasket
handler (https://github.com/dotnet-architecture/eShopOnContainers/blob/dev/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs#L123) which first calls catalog service to get catalog item (by catalog item id from request), then gets or creates basket and then it updates basket with new item added, checking if items with this id has not been already added to basket, and if it has then it only updates quantity of that item in basket.
So quite amount of "business logic" happens in this controller. I know that eShopOnContainers is not strict DDD example, and I wanted to know if this particular pattern/example is "acceptable" when you follow DDD principles?
What I noticed is that it simplifies (and decouples it from catalog service) basket service because it does not have to call catalog service by itself. On the other hand there is some logic (specifically updating quantities instead of adding item which already exists in basket) that for sure should be implemented in basket service and whole basket should (I think) be implemented as aggregate.
So from DDD point of view basket service should receive the request to add new items, then call (asynchronously through event broker would be the best) catalog service and update the basket. Or eventually basket controller could call catalog service to get items from catalog and call basket api to add those items.
While I know that basket service is simplified in this repo/example, I wonder if it's common approach, regarding DDD, that if there is service A that needs some kind of read model from service B to make decision (like basket service need some data from catalog service) then instead of calling (even asynchronously) service B from A, API gateway first calls service B to fetch some read model from it and then it calls service A passing this read model / required data directly to it?