Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 125/ 160
07. Streaming & Real-Time Data Engineering

Kafka Consumers, Consumer Groups, Rebalancing & Offset Management

Scale reads with consumer groups, understand rebalances, and commit offsets correctly.

IntermediateConsumer Groups · Rebalance · Offsets3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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

Loading interactive 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.

Kafka Consumers, Consumer Groups, Rebalancing & Offset Management in one concrete design

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.

Key takeaway: 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

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.

Key takeaway: 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.

How it works, step by step

Step 1 of 4
Consumer Groups

1. 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.

group membership and partition assignment
Key numbers at this step
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

Consumer Groups
Best for: A set of consumers sharing a topic's partitions so at most one current active member handles a partition at a time.

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.

Rebalance
Best for: Partition reassignment after member/topic changes, with cooperative protocols minimizing stop-the-world movement.

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.

Offsets
Best for: A durable per-group partition position that may trail the fetched processing position until downstream work commits.

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 commitSync for those exact offsets; a long model call is split into chunks so max.poll.interval.ms remains 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?
Interview tip: Lead with the data path and failure boundary: 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. Then make the answer operational: 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.

Knowledge check

Loading quiz

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.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
Kafka Producers (Acknowledgments acks, Batching, Compression, Partitioners)
Next topic
Delivery Semantics (At-Most-Once, At-Least-Once, Exactly-Once Semantics)