Video in progress

What is a consumer group for?

A consumer group is a set of consumers that act as one logical reader. Inside the group, partitions are divided among the consumers, so each message is delivered to only one consumer of the group.

📖 Answer

You run one service as 3 pods, all with group.id=order-service. The topic has 6 partitions, so Kafka gives each pod 2. The load is split, and (in the normal case) no message is processed twice.

@KafkaListener(topics = "orders", groupId = "order-service")
public void handle(OrderEvent event) {
    // each pod receives from the partitions assigned to it
}

If another service, say notification-service, reads with its own group.id, it also gets every message. Groups are independent of each other: each has its own offsets.

So inside a group it works like a queue (the load is divided), and across groups it works like pub/sub (everyone gets everything).