Monedula

Scenario 02.1.1 · Subscribe, poll, fetch loop

Kafka consumer poll loop: subscribe, poll, fetch

Consumer groups · Intermediate · about 2 min · Apache Kafka 4.3

A consumer subscribes and polls in a loop; each poll fetches new committed records and advances its position.

Run this scenario in the playground

Caught up · position 3. t+2.400s

All three records have been fetched (position 3). With nothing new to read, further polls return empty until the producer writes again.

Open at this step: step 4, Caught up · position 3

What you start with

A Kafka consumer is not pushed a stream - it drives a poll loop. Here a single consumer subscribes to a topic and repeatedly polls; each poll fetches the next batch of committed records from the broker and advances the consumer's in-memory position.

Step by step

  1. Consumer subscribed · position 0 t+0.000s The consumer c1 has subscribed to 'orders' and is polling in a loop. The log is empty and its position is 0. Open at this step: step 1, Consumer subscribed · position 0
  2. First poll fetches O1 · position 1 t+0.900s O1 was produced and committed; the next poll fetched it and advanced the consumer's position to 1. This poll → fetch → advance step is the consumer's fetch loop. Open at this step: step 2, First poll fetches O1 · position 1
  3. Keeping up with the stream t+1.700s As more records commit, each poll fetches them and advances the position. The consumer reads only committed records (offsets below the high watermark). Open at this step: step 3, Keeping up with the stream
  4. Caught up · position 3 t+2.400s All three records have been fetched (position 3). With nothing new to read, further polls return empty until the producer writes again. Open at this step: step 4, Caught up · position 3

The takeaway

Consumption is pull-based and stateful: the position moves forward one fetched batch at a time, and a consumer only ever sees records up to the partition's high-watermark.

Embed this scenario

Paste this into a blog post, a course page or your team's docs. The scenario plays inside your page, and the link under it points readers to this walkthrough.

<iframe src="https://monedula.dev/kafka-simulator/embed/?scenario=02.1.1" title="Kafka Simulator: Subscribe, poll, fetch loop" width="100%" height="520" style="border:1px solid #d0d0d0;border-radius:8px" loading="lazy"></iframe>
<p><a href="https://monedula.dev/kafka-simulator/scenarios/subscribe-poll-fetch-loop/">Kafka consumer poll loop: subscribe, poll, fetch</a></p>

Further reading

Apache Kafka documentation

More in Consumer groups

All scenarios