Video in progress

Staff 🌱 Spring

How do you decide between synchronous REST and asynchronous messaging (Kafka/RabbitMQ) for communication between services?

If the answer is needed immediately and the caller can't continue without the result, go synchronous; if the work can happen later, there are several consumers, or the services must run independently, go asynchronous. Each has different failure modes.

📖 Answer

I start with one question: can the caller respond to the user without waiting for the answer?

Synchronous (REST/gRPC) fits when:

  • the user needs to see the result right now: "is this promo code valid?";
  • the request is a read, not a command;
  • the chain is short (1–2 steps).

The price is temporal coupling: if B is down, A doesn't work either. Availability multiplies: 99.9% × 99.9% × 99.9% ≈ 99.7%. Every call needs a timeout, a retry policy and a circuit breaker.

Asynchronous (events/messages) fits when:

  • the result can come later: email, a report, a stock reservation, analytics;
  • several services listen to the same event ("order created" → billing, stock, notifications);
  • the sender has to keep working even if the receiver is down for a while;
  • there are sharp traffic spikes, and the queue smooths them out.

The price: eventual consistency (the user sees "order received, being confirmed"), duplicate and ordering problems, harder debugging, and the broker is new critical infrastructure.

Common mistakes:

  • Using async as if it were sync: sending a message and then waiting 30 seconds on a reply topic. That combines the bad sides of both worlds.
  • Putting the whole entity into the event, so consumers become tied to your internal model.
  • "Let's make everything an event", even a plain read. As a result every service keeps a copy of another's data, and keeping them in sync becomes the main job.

A practical rule: commands and queries are often synchronous; facts that have happened ("payment went through") are events. Every event needs an owner, a schema and a versioning rule.