liveBook · Manning

Sequence number

As explained in Apache Kafka in Action

A sequence ID is an ordered identifier assigned to a Kafka message to detect duplicates and verify message order within a partition.

A sequence number is an ordered identifier attached by an idempotent Kafka producer to each message. It helps the partition leader detect duplicates, missing messages, and messages arriving out of order. This matters when a producer does not receive an acknowledgment: retrying may otherwise write the same message twice. section 5.1.3

Sequence numbers work with a producer ID and idempotence. When a previously persisted message is retried, the broker resends the acknowledgment instead of writing it again. When a message arrives out of sequence, the broker sends a negative acknowledgment, prompting the producer to retry. section 5.1.3

Use sequence numbers with these operational boundaries:

  • Enable idempotence with `enable.idempotence=true`; use `acks=all`, retries greater than zero, and no more than five in-flight requests per connection. section 5.1.3
  • Treat ordering as a partition-scoped guarantee: messages must come from the same producer and reach the same partition. section 6.1.1
  • Do not infer ordering across partitions or among messages produced by different producers. section 6.1.1

Enable sequence-based duplicate detection

A console producer can enable idempotence alongside durable acknowledgments: `kafka-console-producer.sh --topic products.prices.changelog.min-isr-2 --bootstrap-server localhost:9092 --producer-property acks=all --producer-property enable.idempotence=true`. If an acknowledgment is lost after persistence, the retry is recognized rather than appended as a duplicate.

How Apache Kafka in Action covers it

How deep it goes
Explains producer and broker checks, ACK/NACK responses, required settings, and partition scope without detailing internal sequence-number encoding.
Examples
Uses an idempotent console producer, a lost-acknowledgment duplicate, and an out-of-order message rejected with a NACK.
What it assumes
Assumes producers, brokers, partitions, acknowledgments, retries, and delivery guarantees; explains idempotence requirements explicitly.
What you can do after
Diagnose/debug with it: identify duplicate and ordering failures, then verify idempotence settings and partition placement.
How it connects
Connects sequence numbers to idempotence, producer IDs, acknowledgments, retries, partitions, and message ordering.

Also explained in

Compare how 3 books explain sequence number →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Apache Kafka in Action. The section links point to the parts of the book it draws on.