# Solution 03 — Consumer groups

*Attempt the exercise first — this file is the post-mortem.*

## What the verified run showed

Both members alive:

```
GROUP          COORDINATOR      STRATEGY  STATE    #MEMBERS
course.workers kafka-1:29092(1) range     Stable   2

CONSUMER-ID  CLIENT-ID  #PARTITIONS
…worker-b…   worker-b   3
…worker-a…   worker-a   3
```

After `Ctrl-C` on worker-b:

```
#MEMBERS 1 — Stable
GROUP          TOPIC         PARTITION  CURRENT-OFFSET  LOG-END  LAG  CONSUMER-ID
course.workers course.groups 0         0               0        0    …worker-a…
course.workers course.groups 1         0               0        0    …worker-a…
course.workers course.groups 2         12              12       0    …worker-a…
course.workers course.groups 3..5      0/0/0           …        0    …worker-a…
```

Counts: worker-a printed **12** records, worker-b printed **0** (all 12 sat
on the sticky Partition:2, which range assignment gave to A).

The Java lesson (`scripts/run.sh lab.ConsumerLesson`):

```
↳ 6 partitions ÷ 3 consumers = 2 each. When consumer-3 closed, the group
  rebalanced: the listener printed revoked→assigned, and the survivors
  picked up its partitions AND its committed offsets.
```

## The understanding checks, answered

1. Within the group: partitions load-balance — the `--members` output
   (3 partitions each, 2 members) is the direct evidence. Across groups:
   broadcast — analytics in Exercise 04 gets its own full copy of every
   record while shipping consumes the same topic; group-isolated offsets
   (Exercise 01's ledger, per group) are the mechanism.
2. B polled, processed, died before commit → the last *committed* offset
   for that partition is what survives → A resumes **from the commit**, so
   B's processed-but-uncommitted record is **re-delivered**. Delivery is
   at-least-once; duplicates are a design consequence, not a bug.
3. One word: **idempotent**. At-least-once + non-idempotent handler =
   double charge. At-least-once + idempotent handler = exactly-once
   *effect* — the practical way production systems get "exactly once".
4. In the default (eager) protocol, a rebalance pauses the **whole group**:
   every member revokes, the coordinator recomputes, all rejoin. In the
   CLI run the pause is seconds; in the Java lesson the lesson prints the
   `revoked→assigned` transitions, and both survivors stop polling between
   them. One member's churn taxes everyone — which is why flapping
   consumers (aggressive restarts, long GC pauses, `max.poll.interval.ms`
   violations) amplify into "the group that will not stay up".

## The skew post-script

Worker-b's zero records were *fair assignment, skewed data* — Exercise 02's
sticky partition put all the work in one partition, and the group can only
share what exists. When a "slow consumer" complaint turns out to be one
partition with all the records, the group is healthy; the *keying* is the
patient.

## What this buys you in production

You can now read a `--describe --state` the way you read a pulse: member
count vs expected, Stable vs Rebalancing, and per-member partition counts
that should be roughly equal. And you know that the rebalance pause is
*group-wide* — which is why rolling deploys of consumer fleets need either
static membership or cooperative rebalancing to stay quiet.
