Skip to content

Consumer groups and partitions

Course: Kafka - chapter 6

A consumer group is a group of consumers that coordinate to consume messages from a Kafka topic.

Purpose:

  • Load Balancing: Distribute the processing load among multiple consumers.
  • Fault Tolerance: If one consumer fails, Kafka automatically redistributes the partitions that the failed consumer was handling to the remaining consumers in the group.
  • Parallel Processing: Consumers in a group can process different partitions in parallel, improving throughput and scalability.

Partitions are subdivisions of a Kafka topic. Each partition is an ordered, immutable sequence of messages that is appended to by producers. Partitions enable Kafka to scale horizontally and allow for parallel processing of messages.

When a message is produced to a Kafka topic, it is assigned to a specific partition. This can be done using a round-robin method, a hash of the message key, or a custom partitioning strategy.

Usually you’ll take things like user id as the message key so all messages from the same user go to the same consumer (so a single user doesnt starve everyone lets say)