21 / 35 · Delivering Changes
Queues and event logs
Follow one sale through a partitioned log and distinguish a consumer's progress from the lifetime of the record.
A sales event needs to reach the report and the inventory checker. The report may later replay yesterday’s sales after a calculation changes. The checker only needs to resume where it stopped. The transport has to represent the shared history and each consumer’s progress separately.
Acknowledgement and retention answer different questions#
In an acknowledged work queue, a message can be delivered to a worker, confirmed by that worker and removed from the queue. If the worker disappears before the broker receives its acknowledgement, the message can be redelivered. Publisher confirms and consumer acknowledgements cover different paths. A publisher confirmation does not establish that a worker applied a sale to its database. RabbitMQ 4.1, Consumer Acknowledgements and Publisher Confirms
A retained event log keeps records after a consumer reads them, subject to retention or compaction policy. Each consumer group can save its own position. It can read earlier records while they are still available. Retention sets a real limit. A consumer that needs data from before the retained start cannot recover that prefix from the log alone. Kafka was designed around this separation between retained messages and consumer progress. Kreps et al., 2011, §3 Apache Kafka 4.1, Introduction
Order belongs to a partition#
A Kafka topic is a named stream split into partitions. Each partition is an ordered log. The offset identifies a position in that partition, so offsets from different partitions do not form a single sequence. If a producer routes all changes of order 101 to the same partition, a reader of that partition sees the order in which those changes were appended. This assumes stable routing for the key. The broker does not infer business time, and no corresponding total order is guaranteed across different partitions. Apache Kafka 4.1, Introduction and Design
Suppose two partitions hold sales. Order 101 appears in P0 at offset 6 and its correction appears at 8. Another order may appear in P1 at offset 6. The two records with offset 6 are distinguished by their partition. To refer to one record unambiguously within this topic, name the partition and offset together. A changed partitioning rule needs a plan to retain the ordering assumptions consumers rely on.
A group owns positions, not the log#
In an ordinary Kafka consumer group, one assigned member reads a partition at a time. Members of the same group can share partitions, while a second group reads the same topic independently. If the topic has two partitions and three group members, at most two members have assigned work for that topic. When a member leaves, another can receive its partition and resume from the group’s saved position. Work after the last saved position can be repeated. Kreps et al., 2011, §3.2 Apache Kafka 4.1, Design
Consider P0 with next committed offset 6 and log end offset 9. With no gaps in this example, offsets 6, 7 and 8 remain, so the offset difference is . A reassigned consumer starts at 6. The group’s offset counts progress in the log. It says nothing by itself about whether a separate destination committed the related work.
Progress is local to a partition
Compaction and control records can make offsets differ from the number of visible application records. Even without such gaps, offset lag is not a duration. Three large records may take longer to process than thousands of small ones. Compare positions to diagnose backlog and use timestamps to discuss freshness.
Next#
A consumer can finish an external write and still restart from an older offset. Delivery and processing guarantees asks what happens at that boundary and how to preserve a sale when it is delivered again.
References#
- Apache Software Foundation. Apache Kafka 4.1 documentation. Introduction and Design. Defines topics, partition order, retained logs and consumer progress.
- RabbitMQ Team. Consumer Acknowledgements and Publisher Confirms. RabbitMQ 4.1 documentation on the producer and consumer confirmation paths.
- Jay Kreps, Neha Narkhede and Jun Rao. Kafka: A Distributed Messaging System for Log Processing, 2011, §3. Describes the original partitioned log and consumer-group model.