liveBook · Manning

Order property

As explained in Apache Kafka in Action

Message order is the sequence relationship in which messages are stored or processed.

A price changelog needs each product’s updates in sequence: a later price must not be processed as though it came first. Kafka preserves message order within a partition, not across an entire topic. This distinction lets partitions spread work across brokers and consumers, but it makes partition choice part of the ordering design. section 4.2.1 section 6.1.1

To keep related updates ordered:

  • Give related messages the same key, such as a product name. Key-based partitioning sends messages with that key to the same partition. section 4.2.1
  • Keep the messages on the same producer and partition, and set enable.idempotence=true. Retries or failures can otherwise disturb ordering even for one producer. section 6.1.1
  • When scaling a consumer group, assign whole partitions to consumers rather than distributing individual messages arbitrarily. section 6.1.1

Read a keyed price changelog

Create a two-partition topic with kafka-topics.sh --create --topic products.prices.changelog.multi-partitions-keys --partitions 2 --replication-factor 1 --bootstrap-server localhost:9092. Produce records with kafka-console-producer.sh using --property parse.key=true and --property key.separator=":". Enter coffee pads:10, cola:2, cola:1, coffee pads:11. Read from the beginning with kafka-console-consumer.sh using --property print.key=true. The product sequences remain ordered within their respective partitions; do not infer a guaranteed order between coffee pads and cola. section 4.2.1

Choose the partition count with future changes in mind. Kafka can increase a topic’s partition count but cannot reduce it. Increasing it changes the key-to-partition calculation, so later messages for a key may land in a different partition from older ones. If order cannot be lost, changing the partition count calls for a new topic and a use-case-specific migration instead. section 6.1.3

Figure 6.3 After changing the number of partitions, the partition number for a particular message key usually changes. In this example, messages with the key circle are now produced to partition 2 instead of partition 1, and messages with the key square are now produced to partition 1 instead of partition 0.
A screenshot of a game

AI-generated content may be incorrect.

The figure shows why adding partitions can move an existing key’s future messages to a different partition. section 6.1.3

How Apache Kafka in Action covers it

How deep it goes
Explains partition-level guarantees, keyed routing, producer requirements, and partition-count changes; leaves migration details dependent on the use case.
Examples
Uses keyed product-price records and a partition-count change to show preserved per-key order and the risk of remapping keys.
What it assumes
Assumes basic familiarity with Kafka topics, partitions, offsets, and consumer groups while showing how to produce keyed records.
What you can do after
Operate/configure it by keying related messages, enabling producer idempotence, and assessing ordering risks before changing partition counts.
How it connects
Connects message order to partitions, message keys, consumer groups, producer idempotence, and horizontal scaling.

Also explained in

Compare how 8 books explain Order property →

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.