Hussain
Hussain

Reputation: 1015

Kafka Topic Partition

Kafka Topic Partition offset position always start from 0 or random value and How to ensure the consumer record is the first record in the partition ? Is there any way to find out ? If any please let me know. Thanks.

Upvotes: 0

Views: 2563

Answers (2)

Matthias J. Sax
Matthias J. Sax

Reputation: 62350

Yes and no.

When you start a new topic, the offset start at zero. Depending on the Kafka version you are using, the offsets are

Furthermore, old log entries are cleared by configurable conditions:

Thus, the first offset might not be zero if old messages got deleted. Furthermore, if you turn on log-compaction, some offsets might be missing.

In any case, you can always seek to any offset safely, as Kafka can figure out if the offset is valid or not. For an invalid offset, is automatically advances to the next valid offset. Thus, if you seek to offset zero, you will always get the oldest message that is stored.

Upvotes: 2

Bector
Bector

Reputation: 1334

Yes, Kafka offset starts from 0 and ends with byte length of the complete record and then next record picks the offset from there onward.

As Kafka is distributed so we can not assure that Consumer will get the data in ordered way.

Upvotes: 0

Related Questions