Bird
Raised Fist0
Kafkadevops~7 mins

Cooperative vs eager rebalancing in Kafka - CLI Comparison

Choose your learning style10 modes available
Introduction
Kafka uses rebalancing to assign partitions to consumers in a group. Cooperative and eager rebalancing are two ways Kafka manages this process to keep data flowing smoothly when consumers join or leave.
When you add a new consumer to a Kafka consumer group and want to minimize message processing pauses.
When a consumer leaves or crashes and you need to redistribute partitions quickly.
When you want to avoid duplicate message processing during rebalancing.
When you want to reduce the time your application is unavailable due to rebalancing.
When you want to choose between faster rebalancing or smoother transitions with less disruption.
Commands
Starts a Kafka consumer using cooperative rebalancing to reduce disruption during partition reassignment.
Terminal
kafka-console-consumer --bootstrap-server localhost:9092 --topic example-topic --group example-group --consumer-property partition.assignment.strategy=org.apache.kafka.clients.consumer.CooperativeStickyAssignor
Expected OutputExpected
Subscribed to topic(s): example-topic [Consumer] Starting consumption with cooperative rebalancing
→
--consumer-property partition.assignment.strategy - Sets the partition assignment strategy to cooperative sticky assignor
Starts a Kafka consumer using eager rebalancing which immediately revokes all partitions and reassigns them.
Terminal
kafka-console-consumer --bootstrap-server localhost:9092 --topic example-topic --group example-group --consumer-property partition.assignment.strategy=org.apache.kafka.clients.consumer.StickyAssignor
Expected OutputExpected
Subscribed to topic(s): example-topic [Consumer] Starting consumption with eager rebalancing
→
--consumer-property partition.assignment.strategy - Sets the partition assignment strategy to sticky assignor (eager rebalancing)
Shows the current partition assignments and consumer group status to verify rebalancing results.
Terminal
kafka-consumer-groups --bootstrap-server localhost:9092 --describe --group example-group
Expected OutputExpected
TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID example-topic 0 100 100 0 consumer-1-1234abcd-5678-90ef-ghij-klmnopqrst /127.0.0.1 consumer-1 example-topic 1 50 50 0 consumer-2-1234abcd-5678-90ef-ghij-klmnopqrst /127.0.0.1 consumer-2
→
--describe - Shows detailed information about the consumer group
Key Concept

If you remember nothing else, remember: cooperative rebalancing reduces downtime by gradually moving partitions, while eager rebalancing moves all partitions at once causing longer pauses.

Common Mistakes
Using eager rebalancing when you have many consumers and want minimal processing pauses.
Eager rebalancing revokes all partitions immediately, causing longer pauses and possible duplicate processing.
Use cooperative rebalancing by setting partition.assignment.strategy to CooperativeStickyAssignor for smoother transitions.
Not setting the partition.assignment.strategy property explicitly and assuming the default fits all cases.
Kafka defaults to eager rebalancing which may cause unnecessary downtime in some applications.
Explicitly set the assignment strategy based on your application's tolerance for downtime and complexity.
Summary
Cooperative rebalancing moves partitions gradually to reduce consumer downtime.
Eager rebalancing revokes all partitions immediately causing longer pauses.
Set partition.assignment.strategy to control the rebalancing behavior in Kafka consumers.

Practice

(1/5)
1. What is the main advantage of cooperative rebalancing in Kafka consumer groups?
easy
A. It reduces consumer pause time by reassigning partitions gradually.
B. It reassigns all partitions at once for faster processing.
C. It eliminates the need for consumer group coordination.
D. It increases the number of partitions automatically.

Solution

  1. Step 1: Understand cooperative rebalancing behavior

    Cooperative rebalancing allows consumers to leave partitions gradually, which reduces the pause time during rebalancing.
  2. Step 2: Compare with eager rebalancing

    Eager rebalancing reassigns all partitions at once, causing longer pauses, unlike cooperative rebalancing.
  3. Final Answer:

    It reduces consumer pause time by reassigning partitions gradually. -> Option A
  4. Quick Check:

    Cooperative rebalancing = gradual partition reassignment [OK]
Hint: Cooperative means gradual, eager means all at once [OK]
Common Mistakes:
  • Confusing eager with cooperative rebalancing
  • Thinking cooperative rebalancing eliminates coordination
  • Assuming rebalancing increases partitions
2. Which configuration property enables cooperative rebalancing in Kafka consumers?
easy
A. group.rebalance.strategy = 'eager'
B. rebalance.policy = 'cooperative'
C. enable.cooperative.rebalance = true
D. partition.assignment.strategy = 'org.apache.kafka.clients.consumer.CooperativeStickyAssignor'

Solution

  1. Step 1: Identify the correct property for assignment strategy

    Kafka uses partition.assignment.strategy to set the rebalance strategy class.
  2. Step 2: Recognize the cooperative assignor class

    The cooperative rebalancing strategy is implemented by org.apache.kafka.clients.consumer.CooperativeStickyAssignor.
  3. Final Answer:

    partition.assignment.strategy = 'org.apache.kafka.clients.consumer.CooperativeStickyAssignor' -> Option D
  4. Quick Check:

    Cooperative assignor class = partition.assignment.strategy = 'org.apache.kafka.clients.consumer.CooperativeStickyAssignor' [OK]
Hint: Look for 'partition.assignment.strategy' with cooperative class [OK]
Common Mistakes:
  • Using incorrect property names
  • Confusing eager and cooperative strategy names
  • Assuming a boolean flag enables cooperative rebalancing
3. Given two consumers in a group using eager rebalancing, what happens when one consumer leaves?
medium
A. All partitions in the group are reassigned immediately, causing a pause.
B. Only the partitions of the leaving consumer are reassigned gradually.
C. The remaining consumer continues without any rebalancing.
D. Partitions are reassigned only after a timeout period.

Solution

  1. Step 1: Understand eager rebalancing behavior on consumer leave

    In eager rebalancing, when any consumer leaves, all partitions are reassigned immediately to maintain balance.
  2. Step 2: Recognize the impact on consumer pause

    This immediate reassignment causes a pause for all consumers during the rebalance.
  3. Final Answer:

    All partitions in the group are reassigned immediately, causing a pause. -> Option A
  4. Quick Check:

    Eager rebalancing = full immediate reassignment [OK]
Hint: Eager means all partitions reassign at once [OK]
Common Mistakes:
  • Thinking only leaving consumer's partitions reassign
  • Assuming no pause occurs
  • Believing reassignment waits for timeout
4. You have a Kafka consumer group using cooperative rebalancing but notice long pauses during rebalances. What is a likely cause?
medium
A. Partitions are being reassigned gradually as expected.
B. The consumer group has only one consumer.
C. Consumers are using the eager assignor instead of cooperative assignor.
D. The rebalance timeout is set too low.

Solution

  1. Step 1: Check the assignor configuration

    If long pauses occur despite expecting cooperative rebalancing, the consumers might be using the eager assignor by mistake.
  2. Step 2: Understand the impact of eager assignor

    Eager assignor causes all partitions to reassign at once, leading to longer pauses.
  3. Final Answer:

    Consumers are using the eager assignor instead of cooperative assignor. -> Option C
  4. Quick Check:

    Long pauses + cooperative expected = eager assignor used [OK]
Hint: Long pauses mean eager assignor, not cooperative [OK]
Common Mistakes:
  • Assuming gradual reassignment causes long pauses
  • Ignoring assignor configuration
  • Blaming rebalance timeout without checking assignor
5. You want to minimize downtime in a Kafka consumer group with frequent consumer joins and leaves. Which strategy and configuration should you choose?
hard
A. Use eager rebalancing with default assignor for simplicity.
B. Use cooperative rebalancing with CooperativeStickyAssignor to reduce pause time.
C. Disable rebalancing to avoid any pauses.
D. Use eager rebalancing but increase session timeout to reduce rebalances.

Solution

  1. Step 1: Identify the goal

    The goal is to minimize downtime during frequent consumer group changes.
  2. Step 2: Choose the appropriate rebalance strategy

    Cooperative rebalancing reduces pause time by reassigning partitions gradually, which suits frequent joins/leaves.
  3. Step 3: Select the correct configuration

    Using CooperativeStickyAssignor enables cooperative rebalancing in Kafka consumers.
  4. Final Answer:

    Use cooperative rebalancing with CooperativeStickyAssignor to reduce pause time. -> Option B
  5. Quick Check:

    Minimize downtime = cooperative rebalancing + correct assignor [OK]
Hint: CooperativeStickyAssignor minimizes downtime with frequent changes [OK]
Common Mistakes:
  • Choosing eager rebalancing for low downtime
  • Disabling rebalancing causing stale assignments
  • Misconfiguring session timeout instead of strategy
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard