Kafka consumers read data by subscribing to topics, getting assigned specific partitions (often as part of a consumer group), and tracking their progress through each partition using offsets.
Key Points: • Consumers subscribe to one or more topics, and Kafka's group coordinator assigns partitions among the members of a consumer group. • Each consumer tracks an offset per partition, marking the last record it has successfully processed, which lets it resume exactly where it left off after a restart. • Consumers can choose to auto-commit offsets periodically or manually commit them after processing, trading convenience for precise control over delivery guarantees. • The auto.offset.reset policy (earliest or latest) determines where a consumer starts reading when it has no previously committed offset. • Consumers poll for new records in a loop, receiving batches of records per partition rather than one at a time, which improves throughput.
Example: A consumer group with four members reading a 12-partition topic might each get assigned three partitions, and if one consumer restarts after a crash, it resumes from its last committed offset instead of reprocessing or skipping data.
Interview Tip: A concise interview answer is:
"Consumers read from Kafka by subscribing to topics, getting partitions assigned through a consumer group, and tracking offsets so they always know where they left off, with the choice between auto-commit and manual offset commits determining how strong their delivery guarantees are."