kafka-python consumer start reading from offset (automatically)
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
A kafka-python consumer does not start from one universal "default offset." The starting position depends first on whether the consumer group already has a committed offset and only then, if no valid committed offset exists, on the auto_offset_reset policy.
The Two Main Cases
When a consumer joins Kafka with a group_id, Kafka first looks for committed offsets for that group and partition.
- If a committed offset exists, the consumer resumes from there.
- If no valid committed offset exists,
auto_offset_resetdecides the fallback behavior.
That is the key mental model. Many offset bugs come from assuming auto_offset_reset always applies, when in reality it is only a fallback.
Basic Group-Managed Consumer
Here is a normal group-managed consumer:
In this setup, earliest matters only when the group has no valid stored offset for a partition. Once offsets are committed, the consumer usually resumes from those commits instead.
What auto_offset_reset Really Means
The two common choices are:
- '
earliest, start from the oldest available record,' - '
latest, start from the end and consume only new records.'
This choice applies only when Kafka cannot resume from a valid committed position. That may happen the first time a group reads a topic, or later if the stored offset is no longer usable because retention has removed the old data.
Start From an Exact Offset With seek
If you need deterministic replay from a specific offset, do not rely on reset policies. Assign the partition manually and seek explicitly.
This bypasses normal group-offset resume behavior and gives you exact control over the starting position.
Reset the Position of a Group-Managed Consumer
Sometimes you still want a group-managed consumer, but you want to move it programmatically before processing. In that case, wait for partition assignment and then seek.
The initial poll matters because assignment usually happens during polling. Without assigned partitions, there is nothing to seek.
Use a New Group for Experiments
A very practical debugging trick is to use a fresh throwaway group_id when you want to see auto_offset_reset in action. If you reuse an old group, the previously committed offsets will often override the reset policy and make the behavior look confusing.
That is why replay and debugging often work better in a temporary consumer group than in a long-lived production one.
Be Careful With Auto-Commit
During replay or experiments, automatic commits can silently store progress you did not intend to keep. If you are investigating offsets or replaying history, it is often safer to disable auto-commit until you know exactly what should be persisted.
That way the consumer does not accidentally rewrite the group's position just because you ran a debugging script once.
Common Pitfalls
A common mistake is expecting auto_offset_reset to override an existing committed offset. It does not.
Another issue is calling seek before the consumer has partitions assigned. In group-managed mode, that usually means polling first.
Teams also often leave enable_auto_commit=True during replay experiments and then wonder why the group's position changed afterward.
Summary
- A
kafka-pythonconsumer resumes from committed offsets when they exist. - '
auto_offset_resetapplies only when no valid committed offset is available.' - Use
seekfor exact-offset replay instead of relying on reset policy. - In group-managed mode, wait for assignment before seeking.
- Disable auto-commit during replay or debugging when you do not want to persist the new position.
Related reading
- Kafka-python get number of partitions for topic
- Kafka-python How to consume json message
- kafka-python producer is not able to connect
- kafka-python raise UnrecognizedBrokerVersion Error
- kafka-python read from last produced message after a consumer restart
- Kafka-python retrieve the list of topics
- kafka-server-stop.sh not working when Kafka started from Python script
- Kafka->Spark->Cassandra forcing data locality

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.