Reputation: 642
I have built a fairly simple pair of microservices using Spring. It consists of main-service which has a ProductRepository and a discount-service which has a DiscountRepository containing product discounts by category.
When I call the main-service to get product by id, it pulls product details, then calls the discount-service and gets a discounted price. Which then is sent back to the main-service, added to the product details dto and presented to the customer together with the rest of the product details.
My question is: What is the best practice for sending a post request to update the DiscountRepository? Should I send it through the main-service or should I call the discount-service directly?
I appreciate that all this could have been done in one microservice, but I am practising connecting multiple microservices using @Feignclient and hence came up with this question.
Cheers!
Upvotes: 0
Views: 541
Reputation: 77206
There's no single "best practice" that applies; you will have to make a judgment about how you intend your API to operate.
For example, you might decide to have a single "storefront" API where everything is managed, and in this case the /discounts
requests might get forwarded on to the Discounts microservice.
Alternately, you might decide that "store admin" is a separate concern and operates entirely inside your application domain, with no public access. In this case, you wouldn't forward /discounts
but rather would have a client or Admin microservice make calls to Discounts directly.
Which approach is more suitable depends on your business priorities.
Upvotes: 1