Junior — Middle
Can you give a scenario where using synchronous calls between microservices is justified?
sobes.tech AI
Answer from AI
Synchronous calls between microservices are justified when it is necessary to obtain the result of an operation immediately for further processing. For example, when placing an order in an online store, the payment service must synchronously confirm a successful transaction before the order is finally accepted and sent to the warehouse. In such cases, a delay due to waiting for a response is acceptable, as subsequent steps depend on the result of the call.
Scenario example:
- The client sends a request to create an order.
- The order service synchronously calls the payment service.
- If the payment is successful, the order is confirmed and sent for processing.
- If the payment fails, the order is rejected.
This approach ensures consistency and simplifies processing logic but requires considering possible delays and communication failures.