Search code examples
apache-kafkatimestampoffset

Is Kafka timestamp order corresponding to the offset?


We use kafka for our message queue,Our business required that message timestamp must with the same order with the offset, that means: if there are message m1 and message m2, and (m1.timestamp


Solution

  • It depends on the timestamp type used, there are two types:

    • CreateTime - timestamp is assigned when producer record is created, so before sending. There can be retries, so there is no guarantee that ordering is preserved.
    • LogAppendTime - timestamp is assigned when record is appended to the log on the broker. In that case ordering per partition is preserved. Multiple messages might get the same timestamp assigned.

    By default, CreateTime is used. To change this, set log.message.timestamp.type for broker or message.timestamp.type for particular topic.