What are synchronous and asynchronous communication in microservices?
Short answer: Synchronous Communication: In synchronous communication, one service sends a request to another service and waits for the response before continuing with its processing. The service that sends the request is blocked until it receives a response from the other service. This is typically used for real-time communication, like RESTful APIs over HTTP.
Example code
A User Service might request the Payment Service to verify a payment before processing an order. The User Service waits until it receives the response. Asynchronous Communication: In asynchronous communication, one service sends a request to another service but does not wait for a response. The requesting service continues processing while the service handling the request processes it in the background. This is typically used in event-driven architectures with message brokers. Example: An Order Service might send a message to a queue (via RabbitMQ or Kafka) about a new order, and the Inventory Service processes it at its own pace, independently of the Order Service.
Real-world example (ShopNest)
ShopNest splits Catalog, Cart, Order, and Payment into services so teams can deploy catalog changes without redeploying payments.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png