In our microservice architecture, this is how requests flow.
Service Layer: Requests hit this layer from public LB. Also, response composition is performed here.
API Gateway: The core job of API gateway is to make parallel calls to respective microservices.
Please note Usually response composition is done at API Gateway. However, we intentionally moved composition at service layer due to frequent changes in compositions.
Being in the automotive domain, we deal with vehicles, dealers, leads etc. Now, there is a confusion on when to prefer synchronous over asynchronous and vice versa. Let me take an example of below two microservices.
DealersService: This service holds all the information about dealers.
LXMSService: This service is responsible for processing leads we capture on our platforms and send it to respective clients(dealers).
While lead is getting captured, we want to show the list of dealers user can choose from. The logic of showing dealers may vary client to client. These logics are configured in LXMS, and we store only dealer ids in this service(LXMS).
Now there can be two possible ways to show dealers!
Possibility 1: Synchronous way
Step 1: Make a call to LXMS microservice
Step 2: Get a list of dealer ids
Step 3: Pass these list if dealer ids to Dealer microservice to resolve.
Step 4: Dealer microservice returns id, name of a dealer which we show to the user.
Possibility 2: Asyncronous way
We remove the dependency by storing the dealer name in LXMS microservice. And maintain consistency using Pub/Sub. This way we are isolating LXMS and removing run-time dependencies from the service layer.
Here are the questions
Which approatch we should go with & why?
What is the problem in making sequential calls?
In first approatch, when service layer making sequential calls. Can we call microservices independent?
Isolation comes at the additional overhead of data synching using pub/sub. Is the isolation worth this overhead?
- When to prefer synchronous over asynchronous and vice versa?