Bookmarks

Message broker

An intermediary server that accepts messages from senders, stores them and delivers them to receivers, offloading and tying together the parts of a distributed system.

Also: message broker, message queue broker

checked 8 Nov

All terms

Services do not call each other directly: the sender puts a message on the broker and immediately carries on, while the receiver picks it up whenever it is ready. The broker decouples the parts of the system in time and speed — one service failing does not stop the others, and a traffic spike is absorbed by the queue.

What the broker does

  • Accepts messages from producers and stores them until they are delivered.
  • Routes them: by queue name, topic or routing rules.
  • Hands messages to consumers — each takes one when ready.
  • Waits for an acknowledgement (ack) and redelivers if none arrives.
  • Moves “poison” messages to a separate dead-letter queue.

Queue and log

Two approaches to storing messages. A classic queue: a message goes to the first free worker and is deleted once acknowledged — that is how RabbitMQ works. A log: messages are appended to the end, read by offset and kept until the retention period expires — that is how Kafka and Redis streams (Stream) work. You can re-read a log, several times over and from any position, and a group of workers splits the log’s partitions between them.

PropertyQueueLog
Where it landsinto a named queueinto a topic partition, appended to the end
After deliverydeleted once acknowledgedkept until the retention period ends
Who receives iteach message goes to one workera group shares partitions, subscribers read everything
Re-readnoyes, from any offset

Types of brokers

  • RabbitMQ — AMQP 0-9-1 exchanges and bindings: direct, fanout, topic, headers.
  • Kafka — a distributed log with partitions and replication, streaming of large flows.
  • NATS — a lightweight broker with pub/sub, request/reply and JetStream streams.
  • Cloud services: Amazon SQS, Google Cloud Pub/Sub, Azure Service Bus.

Example

After an order, an online shop publishes order.created. Three workers read it independently: one reserves stock, another takes the payment, the third sends an email. If payment fails, the broker returns the message and retries a minute later; if the mail server is down, the emails go out once it is back up. A Black Friday spike piles up in the queue, and the workers clear it at their own pace.

Sources

the term is written from these pages

Verified 8 Nov

Not to be confused with

what it is mixed up with and how it differs

  • message queue

    A broker is a server that hosts queues, plus routing and transformations; a queue is one of its mechanisms.

  • publish–subscribe (pub/sub)

    Pub/sub is an interaction style that a broker supports alongside queues; in a queue, each worker gets its own message.

In depth in the references

where the topic is covered in detail