Yannis
Yannis

Reputation: 95

How to make cross treatments on microservices

I'm learning about microservices, and I don't understand how to structure.

Imagine that we are doing an ecommerce application. We are going to have one service for catalog (with products), one service for there prices, one service for promotions and one for shoppingcart.

My question is : which service is in charge of applying the promotions on the shoppingcart cause this treatment need datas from shoppingcart service and from promotion service and must save results (shopping cart with new price) somewhere (but where ?).

Thanks for any help !

Upvotes: 0

Views: 98

Answers (1)

Binary
Binary

Reputation: 112

let's assume that each microservice has it own Bounded Context, so it has its own business logic and database totally separated and all your microservices are loosely coupled.

your shopping cart is responsible for calculating the price as it is the main responsibility of that microservice so it is the service that will apply the promotion too as it is the main responsibility of the shopping cart.

but to recalculate the price after promotion it has to keep and maintain some data related to the promotions. if you are using Event-driven design, you can send an event when you add/update or delete a promotion to the shopping cart.

or you can call an endpoint at promotion microservice to check the discount rate or percentage at runtime but at that point, your shopping cart microservice will be coupled with the promotion microservice.

there are some pros and cons with each approach and it depends on your design

Upvotes: 2

Related Questions