Video in progress
What is the difference between pub/sub (a topic) and a point-to-point queue?
In a queue, only one consumer gets each message — it's for splitting work among workers. In pub/sub, every subscriber gets its own copy of the message — so several services can process the same event independently.
📖 Answer
Two different jobs, two different models.
Queue. There are 1000 "resize this image" tasks and 5 workers. Each task must be done by one worker, not twice. Add workers and the work goes faster. A plain queue in RabbitMQ or SQS works like this.
Pub/sub. An "order created" event. The inventory service, the email service and analytics each have to process it on their own. One message, three copies. Adding a new subscriber doesn't require changing the producer.
Kafka gives you both with a single mechanism: the consumer group. Within one group, partitions are divided among the consumers (like a queue), while different groups each get every message (like pub/sub).
topic: orders
group "inventory" -> 3 pods, messages are divided among them
group "email" -> 2 pods, gets every message on its own
group "analytics" -> 1 pod, gets every message on its own
A spot where people often slip in interviews: in pub/sub, "someone received it" doesn't mean "everyone received it". Each subscriber has its own state (an offset or its own queue), and if one is slow it doesn't hold up the others. In RabbitMQ, pub/sub is built with a fanout exchange and a separate queue per service.
Sign up to mark studied questions and save your progress.