Kafka Partition vs Consumer Group: Which Consumption Mode to Use?
This article explains how Kafka clients can request data via RPC, compares the partition consumption mode with the consumer‑group mode, outlines their protocols, server‑side processing, advantages, drawbacks, and provides guidance on when to choose each approach.
1 Partition Consumption Mode
Clients written in any language can send RPC requests directly to the Kafka server using Kafka's protocol to fetch data. The server receives the request, constructs an RPC response, and returns it to the client, which then parses the response to obtain the messages.
Key Kafka protocols involved include:
FetchRequest / FetchResponse – for retrieving messages.
OffsetRequest / OffsetResponse – for obtaining offsets.
OffsetCommitRequest / OffsetCommitResponse – for committing offsets.
MetadataRequest / MetadataResponse – for fetching metadata.
ProducerRequest / ProducerResponse – for producing messages.
1.1 Server‑Side Implementation
The server processes each RPC request, builds the appropriate response, and sends it back. The client is responsible for managing offsets, handling errors (e.g., leader changes), and implementing its own load‑balancing strategy.
2 Consumer‑Group Mode
In the consumer‑group model, clients also send RPC requests, but the server handles many responsibilities internally.
2.1 Workflow
When a consumer group requests data, the Kafka server aggregates messages into a FetchedDataChunk iterator and returns it. The client simply iterates over this iterator to consume messages.
The server periodically commits offsets via an internal scheduler, so the client does not need to manage offsets.
Error handling, such as leader failover, is performed by the server.
Load‑balancing among consumers in the group is managed by the server.
Monitoring tools like Kafka Offset Monitor and Kafka Manager are built on top of the consumer‑group model.
3 Summary
3.1 Characteristics of Partition Consumption Mode
Clients specify topic, partition, and offset, then send RPC requests to consume.
Clients must manually commit offsets.
Clients must handle errors themselves (e.g., leader changes).
Clients need to implement their own consumer load‑balancing logic.
3.2 Characteristics of Consumer‑Group Mode
Consumption also occurs via RPC requests, but the server abstracts the process.
The server packages messages into FetchedDataChunk objects and returns an iterator for the client to consume.
The server automatically commits offsets periodically; clients do not manage offsets.
The server handles error recovery and consumer load‑balancing.
Many monitoring tools rely on this mode.
Therefore, prefer the consumer‑group mode unless you need to manage offsets yourself (e.g., to implement custom delivery semantics) or handle errors according to specific business requirements.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
JavaEdge
First‑line development experience at multiple leading tech firms; now a software architect at a Shanghai state‑owned enterprise and founder of Programming Yanxuan. Nearly 300k followers online; expertise in distributed system design, AIGC application development, and quantitative finance investing.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
