Video in progress

What's the difference between synchronous and asynchronous communication between services?

In synchronous communication the caller waits for the response (HTTP, gRPC). In asynchronous communication it drops a message to a broker and moves on, and the receiver processes it in its own time (Kafka, RabbitMQ).

📖 Answer

Synchronous is like a phone call: both sides have to be "online" at that moment.

// order-service waits for the payment result
PaymentResult r = paymentClient.charge(orderId, amount);

Asynchronous is like leaving a letter:

// order-service publishes an event and doesn't wait
kafkaTemplate.send("order-created", orderId.toString(), event);

When to pick which:

  • the user needs to see the result right now (price, stock, login): usually synchronous;
  • work where you can say "done, we'll let you know later" (email, reports, bonus calculation): asynchronous.

The big plus of asynchronous: even if the receiving service is down for 10 minutes, the caller keeps working, because the messages wait in the broker. With synchronous, if payment goes down, order returns an error too.

The downside is that the result isn't known right away and errors are harder to trace.