Full Byte Developer.

What happens when you send a message to Kafka

One keyed order followed through Kafka: partition, leader, offset, copies, and the offset a consumer group commits.

Published here , tested on Apache Kafka 4.1.0 (1 KRaft controller + 3 brokers) in Docker 29.4.0 on macOS 27.2 · 7 sources

Kafka keeps every message in a log, and reading a message does not remove it, so a second service can still read it later [1]. This page follows one order through a three-broker cluster, with the numbers from the run shown in the video: Apache Kafka 4.1.0 in Docker, three brokers and one KRaft controller, recorded on 2026-11-16.

Create a topic with three partitions

A topic is split into partitions, and each partition is a separate ordered lane of messages [1]. The video's topic is orders, with three partitions and three copies of each. The create command follows the operations docs [6].

bash
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 3 --replication-factor 3
bash
bin/kafka-topics.sh --describe --topic orders --bootstrap-server localhost:9092

You should see one line per partition with its Leader, Replicas and Isr. In the video's run, partition 1 printed Leader: 2 Replicas: 2,3,1 Isr: 2,3,1.

Send one order with a key

The order has the key user-42. Per the Kafka introduction, events with the same key are written to the same partition [1], and Kafka keeps the order of events inside one partition [1]. That is why all of one user's orders stay in order. The producer hashes the key to choose the partition; in the run, user-42 landed in partition 1, and so did every other user-42 order.

Only one broker takes writes for a partition. Per the design docs, each partition has a single leader, and all writes go to it [3]. For partition 1 that was broker 2.

Find the offset the leader gave it

The leader appends the message to the end of the partition's log. Each slot in the log has a number, the offset. In the run, the order landed at offset 1447, right after a batch that ended at 1446. The log is an ordinary file on broker 2's disk, /tmp/kafka-logs/orders-1/00000000000000000000.log (35,199 bytes at that moment).

Check the copies on the other brokers

One copy on one machine is not enough. Per the design docs, followers fetch from the leader the way a normal consumer does and apply the messages to their own log [3]. In the run, brokers 3 and 1 each held the order at the same offset, 1447.

The producer's OK depends on those copies. The default is acks=all: the leader waits for the full set of in-sync replicas before it answers [4]. The run's in-sync set for partition 1 was brokers 2, 3 and 1.

Read it with a consumer group and check the commit

Consumers read in groups. The group in the video is called billing. After it reads offset 1447, it commits 1448: the committed offset is the next message the application will read [7]. Kafka stores that position as a message in an internal topic [3].

bash
bin/kafka-console-consumer.sh --topic orders --group billing --from-beginning --bootstrap-server localhost:9092
bash
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group billing

You should see a row for each partition with CURRENT-OFFSET, LOG-END-OFFSET and LAG [6]. In the run, partition 1 showed CURRENT-OFFSET 1448, LOG-END-OFFSET 1448 and LAG 0.

Restart the reader and see where it resumes

Reading did not remove the order. It stays in the log until retention removes it, and the broker default log.retention.hours is 168, which is 7 days [5]. Another group can read the same message from its own offset [1].

When billing came back in the run, it resumed at its saved offset: the first record it read was offset 1448, the next order from user-42.

What happens to this order when broker 2 dies is in part 2: when a Kafka OK means your message is saved.

Send this to the friend who uses Kafka at work but never traced where one message goes.

Keep this guide

By Full Byte Developer

Filed under Dev explainers

Questions about this guide

Does Kafka delete a message once a consumer reads it?

No. Per the Kafka introduction, events are not deleted after consumption. A per-topic retention setting decides how long they stay, and the broker default `log.retention.hours` is 168 (7 days).

How does Kafka pick the partition for a message?

When the message has a key, the producer hashes the key, so every message with the same key goes to the same partition while the partition count stays the same. Kafka keeps order within one partition.

Which offset does a consumer group commit?

The offset of the next message it will read. A group that read offset 1447 commits 1448.

When does the producer hear OK?

With the default `acks=all`, after the full set of in-sync replicas has the record. What that means when a broker dies is the subject of part 2.

Sources

Next in this stack