Components involved:
- Mobile Client
- Microservices
- API Gateway
Lets say I have 2 microservices for now. Each of them beingmicroservice is a Flask application exposing a RESTful API. When a request is made by the mobile client, it is sent to the API Gateway.
Let us assumeOne of the request involves 2 microservicesmost important tasks of the system is to perform the furniture selection and furniture placement algorithms (Service A and Service Bas shown below). The output given by Service B depends onselection takes place first and provides the output of Service Ato the placement algorithm which should give the result to the user.
Once the API Gateway has the request, I have 2 options:
The API Gateway sends a request to Service A. Waits for its response. Once it receives the response, it sends a request to Service B. Gets the response and returns it to the client.
The API Gateway sends a request to Service A. Service A does the required processing and then sends a request to Service B. When Service B responds, Service A sends response to the API Gateway and the API Gateway returns it to the client.
The API Gateway sends a request to Selection Algorithm Service. Waits for its response. Once the API Gateway receives the response, it sends a request (along with the response received from the previous request) to the Placement Algorithm Service. Gets the response and returns it to the client. Illustration below:
What is the best way handle the request?
- The API Gateway sends a request to the Selection Algorithm Service which does the required processing and then sends a request to the Placement Algorithm Service along with the result. Once Placement Algorithm Service completes, it responds back to the Selection Algorithm which sends the response back to the API Gateway and the API Gateway returns it to the client. Illustration below:
Also, if at all 2 microservices wanted to communicate with each other, what method would be used?
