Kafka Consumers, Consumer Groups, Rebalancing & Offset Management
Scale reads with consumer groups, understand rebalances, and commit offsets correctly.
In plain words
Group membership and partition assignment. Next, records from committed/high-water offset. Finally, progress and group liveness.
Think of it like…
A consumer group divides logbooks among readers, and the offset is a bookmark; moving the bookmark before writing the notes destroys recovery, while stopping polling too long gives the book to someone else.
Where you’ve seen it
A consumer processes a bounded batch into a transactional warehouse upsert, then calls commitSync for those exact offsets; a long model call is split into chunks so max.poll.interval.ms remains above its worst-case pause.
Words you’ll hear
- Consumer Groups
- A set of consumers sharing a topic's partitions so at most one current active member handles a partition at a time.
- Rebalance
- Partition reassignment after member/topic changes, with cooperative protocols minimizing stop-the-world movement.
- Offsets
- A durable per-group partition position that may trail the fetched processing position until downstream work commits.
- Operational boundary
- Committing offsets before the sink makes a crash lose events, committing after unbounded processing causes duplicates, and max-poll behavior can repeatedly evict a slow member into a rebalance loop. Commit only after durable idempotent sink success, tune fetch and poll intervals to processing time, use static/cooperative assignment when possible, and separate health lag from merely high throughput volume.
Visual diagram
Theory & deep dive
Consumer Groups: the working mechanism
Kafka consumer groups assign partitions to live members, each member fetches sequential offsets, commits progress, and triggers a cooperative or eager rebalance when membership/subscriptions change.
Group membership and partition assignment. Records from committed/high-water offset, then sink, dedupe, then stage offsets; this exposes the state governed by Offsets.
A consumer processes a bounded batch into a transactional warehouse upsert, then calls commitSync for those exact offsets; a long model call is split into chunks so max.poll.interval.ms remains above its worst-case pause.
Kafka Consumers, Consumer Groups, Rebalancing & Offset Management: failure mode and production response
Committing offsets before the sink makes a crash lose events, committing after unbounded processing causes duplicates, and max-poll behavior can repeatedly evict a slow member into a rebalance loop.
Commit only after durable idempotent sink success, tune fetch and poll intervals to processing time, use static/cooperative assignment when possible, and separate health lag from merely high throughput volume. Track Consumer lag as "log end offset minus committed or current processed offset", and make max.poll.interval visible to the dataset owner.
How it works, step by step
Step 1 of 41. Subscribe/join
Group membership and partition assignment. Kafka consumer groups assign partitions to live members, each member fetches sequential offsets, commits progress, and triggers a cooperative or eager rebalance when membership/subscriptions change.
- Consumer lag
- log end offset minus committed or current processed offset
- Rebalance
- Partition reassignment after member/topic changes, with cooperative protocols minimizing stop-the-world movement.
When to use it & trade-offs
What it is
Kafka consumer groups assign partitions to live members, each member fetches sequential offsets, commits progress, and triggers a cooperative or eager rebalance when membership/subscriptions change. A consumer processes a bounded batch into a transactional warehouse upsert, then calls commitSync for those exact offsets; a long model call is split into chunks so max.poll.interval.ms remains above its worst-case pause.
Why it matters: Committing offsets before the sink makes a crash lose events, committing after unbounded processing causes duplicates, and max-poll behavior can repeatedly evict a slow member into a rebalance loop. Commit only after durable idempotent sink success, tune fetch and poll intervals to processing time, use static/cooperative assignment when possible, and separate health lag from merely high throughput volume.
When to reach for it
- Scale reads with consumer groups, understand rebalances, and commit offsets correctly.
- Choose Consumer Groups because it provides this capability: A set of consumers sharing a topic's partitions so at most one current active member handles a partition at a time.
- Keep evidence for Consumer lag at "log end offset minus committed or current processed offset" so the last production stage-Commit/heartbeat - progress and group liveness-remains testable.
When to avoid or be careful
- Committing offsets before the sink makes a crash lose events, committing after unbounded processing causes duplicates, and max-poll behavior can repeatedly evict a slow member into a rebalance loop.
- Do not conflate Rebalance with Consumer Groups. The second concept contributes different behavior: Partition reassignment after member/topic changes, with cooperative protocols minimizing stop-the-world movement.
- Release only after this guardrail is in place: Commit only after durable idempotent sink success, tune fetch and poll intervals to processing time, use static/cooperative assignment when possible, and separate health lag from merely high throughput volume.
Consumer Groups / Rebalance / Offsets - roles, limits, and operating cost
Strengths: A set of consumers sharing a topic's partitions so at most one current active member handles a partition at a time. Kafka consumer groups assign partitions to live members, each member fetches sequential offsets, commits progress, and triggers a cooperative or eager rebalance when membership/subscriptions change.
Watch out: Committing offsets before the sink makes a crash lose events, committing after unbounded processing causes duplicates, and max-poll behavior can repeatedly evict a slow member into a rebalance loop.
Strengths: Partition reassignment after member/topic changes, with cooperative protocols minimizing stop-the-world movement. In this workflow it supports: Process atomically - sink, dedupe, then stage offsets.
Watch out: The operating cost is real: must exceed worst normal processing gap.
Strengths: A durable per-group partition position that may trail the fetched processing position until downstream work commits. Its output can be checked with Active consumers.
Watch out: Operating guardrail: Commit only after durable idempotent sink success, tune fetch and poll intervals to processing time, use static/cooperative assignment when possible, and separate health lag from merely high throughput volume.
Interview signals & numbers to know
When this topic comes up
- “Where is the failure boundary for Consumer Groups, and how would Consumer lag reveal it?”
- “Why is Rebalance distinct from this behavior: a durable per-group partition position that may trail the fetched processing position until downstream work commits?”
- Production clue: Committing offsets before the sink makes a crash lose events, committing after unbounded processing causes duplicates, and max-poll behavior can repeatedly evict a slow member into a rebalance loop.
- Design probe: Commit only after durable idempotent sink success, tune fetch and poll intervals to processing time, use static/cooperative assignment when possible, and separate health lag from merely high throughput volume.
Benchmarks & rules of thumb
- Consumer lag
- log end offset minus committed or current processed offset
- max.poll.interval
- must exceed worst normal processing gap
- Active consumers
- cannot exceed useful assigned partitions for one group
Common mistakes & follow-ups
Common interview mistakes
- Committing offsets before the sink makes a crash lose events, committing after unbounded processing causes duplicates, and max-poll behavior can repeatedly evict a slow member into a rebalance loop.
- Reporting success from a job exit code without checking Consumer lag and max.poll.interval.
- Treating this example as complete without replay, rollback, or access boundaries: A consumer processes a bounded batch into a transactional warehouse upsert, then calls
commitSyncfor those exact offsets; a long model call is split into chunks somax.poll.interval.msremains above its worst-case pause.
Likely interviewer follow-ups
- How would you prove this contract instead of only checking that the command ran: A set of consumers sharing a topic's partitions so at most one current active member handles a partition at a time.
- What does the recovery plan do when this occurs? Committing offsets before the sink makes a crash lose events, committing after unbounded processing causes duplicates, and max-poll behavior can repeatedly evict a slow member into a rebalance loop.
- When is Consumer Groups insufficient for max.poll.interval, and what does adding Rebalance cost in Consumer lag?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Kafka Consumers, Consumer Groups, Rebalancing & Offset Management with data engineer interview Q&A and hands-on practice.