Kafka reference
Consumer groups
Rules worth memorising
- Within a group, each partition has exactly one consumer. One consumer may own many partitions.
- Maximum parallelism equals partition count. Extra consumers sit idle.
- Different groups each read every event, independently.
- Same
group.idshares the work. Differentgroup.ids each get a full copy of the stream.
What triggers a rebalance
- A member joins the group.
- A member leaves or fails.
- A subscribed topic's partition count changes.
- A subscribed topic is created or deleted.
Configs
| Config | Default | Effect |
|---|---|---|
group.id | null | Names the group. Required for subscribe() group management. |
group.protocol | classic | classic or consumer. With consumer, the broker assigns partitions. |
partition.assignment.strategy | RangeAssignor, CooperativeStickyAssignor | Client-side assignors, classic protocol only. Range is used by default. |
group.remote.assignor | null | Picks a server-side assignor, such as uniform or range. Consumer protocol only. |
Range assignor
Per topic: partitions in numeric order, consumers in sorted order, and any remainder goes to the first consumers. With 2 consumers and 2 topics of 3 partitions each, the split is 4 and 2.
Commands
kafka-consumer-groups.sh --bootstrap-server HOST:9092 --list
kafka-consumer-groups.sh --bootstrap-server HOST:9092 --describe --group G
kafka-consumer-groups.sh --bootstrap-server HOST:9092 --describe --group G --members --verbose