Video in progress

What is a message broker, and what problem does it solve in microservices?

A broker is a separate system between services that accepts, stores and delivers messages (Kafka, RabbitMQ). It decouples the sender and the receiver in time: even if the receiver is down, the message isn't lost.

📖 Answer

Without a broker, after an order order-service would have to call the email, bonus and analytics services one by one. If one of them is slow, the order gets slow too; if one is down, you have to decide what to do.

With a broker, order-service writes one message: "order created". Anyone who needs it subscribes on their own.

What a broker gives you:

  • decoupling: the sender doesn't know the receivers;
  • buffering: when load spikes, messages wait in the queue and the consumer reads at its own pace;
  • reliability: the message is written to disk, and the consumer picks up where it left off after a restart.

But it isn't free: the broker is itself part of the system, so you have to monitor it, tune retention, and be ready for duplicate messages. Many brokers deliver "at least once", which means one message can arrive twice.