Sobes.tech
Junior — Middle

What are the differences between a topic and a queue in messaging systems?

sobes.tech AI

Answer from AI

In messaging systems (e.g., RabbitMQ, Kafka), a topic and a queue serve different message delivery models.

  • Queue — a structure where messages are distributed among consumers on a "one of many" (point-to-point) basis. Each message from the queue is received by only one consumer. This is convenient for load balancing.

  • Topic — a publish-subscribe model. Messages sent to a topic are delivered to all subscribers. Each subscriber receives a copy of each message.

Example:

  • If you have a task queue with multiple workers, the message will go to only one of them.
  • If you have a news topic with several clients subscribed, all of them will receive each message.

Thus, the main difference is the method of message delivery: a queue ensures distribution among consumers, while a topic provides broadcast to all subscribers.

What are the differences between a topic and a queue… - sobes.tech