コンシューマーグループとリバランシング
Kafkaのコンシューマーグループが消費をスケールさせる方法、パーティションの割り当て、リバランス時の動作をSpring Kafkaを念頭に理解します。
「コンシューマーグループとリバランシング」はCoddyKit上の無料Advanced Spring Boot 4: Event-Driven Architecture (Kafka)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Advanced Spring Boot 4: Event-Driven Architecture (Kafka)コースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Why Consumer Groups?
A consumer group lets multiple consumer instances share the work of reading a topic. Kafka assigns each partition to exactly one consumer in the group.
Group ID
Consumers join a group by sharing a group.id. Kafka tracks the offset position per group, so each group reads the topic independently.
spring.kafka.consumer.group-id=order-servicePartitions Drive Parallelism
The number of partitions sets the maximum parallelism. With four partitions, at most four consumers in a group can work at once.
topic orders: 4 partitions
group with 4 consumers -> 1 partition eachExtra Consumers Idle
If a group has more consumers than partitions, the extras sit idle. Scale partitions to scale consumption beyond the current limit.
6 consumers, 4 partitions -> 2 idleWhat Triggers a Rebalance
A rebalance reassigns partitions when group membership changes.
- A consumer joins or leaves
- A consumer is considered dead
- Partitions are added
Rebalance Cost
During a rebalance, consumers stop processing briefly while partitions are reassigned. Frequent rebalances hurt throughput.
Heartbeats and Liveness
Consumers send heartbeats. Missing them past session.timeout.ms marks a consumer dead and triggers a rebalance.
session.timeout.ms = 10000
heartbeat.interval.ms = 3000Poll Loop Health
If processing between polls exceeds max.poll.interval.ms, the consumer is evicted. Keep per-message work bounded or increase the limit.
max.poll.interval.ms = 300000Committing Offsets
Offsets record progress per partition per group. Spring Kafka can auto-commit or commit manually after successful processing for at-least-once delivery.
spring.kafka.consumer.enable-auto-commit=falseCooperative Rebalancing
The cooperative rebalance protocol reassigns only the partitions that must move, avoiding a full stop-the-world reassignment.
partition.assignment.strategy=CooperativeStickyAssignorSpring Kafka Listeners
A @KafkaListener joins the configured group automatically; running multiple app instances scales the group with no code change.
@KafkaListener(topics = "orders", groupId = "order-service")
void onOrder(Order o) { ... }Quick Check
Reason about parallelism.
Recap
You learned that a consumer group shares a topic by assigning each partition to one consumer, so partition count caps parallelism. Rebalances reassign partitions when membership changes and briefly pause processing; heartbeats and poll intervals govern liveness. Cooperative rebalancing and manual offset commits keep Spring Kafka consumers efficient and reliable.
よくある質問
「コンシューマーグループとリバランシング」レッスンは無料ですか?
はい。「コンシューマーグループとリバランシング」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Advanced Spring Boot 4: Event-Driven Architecture (Kafka)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Advanced Spring Boot 4: Event-Driven Architecture (Kafka)コースには全4レッスンが含まれています。
「コンシューマーグループとリバランシング」で何を学びますか?
Kafkaのコンシューマーグループが消費をスケールさせる方法、パーティションの割り当て、リバランス時の動作をSpring Kafkaを念頭に理解します。 ブラウザで直接実行するハンズオンコードでAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Advanced Spring Boot 4: Event-Driven Architecture (Kafka)を始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「コンシューマーグループとリバランシング」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)レッスンでコードを書いて実行できますか?
はい。すべてのAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Kafkaアーキテクチャの概要
- トピック、パーティション、オフセット
- DockerでローカルKafkaをセットアップする
- コンシューマーグループとリバランシング