Lab · Messaging
Kafka: partitions, replication & delivery
Producers append to a topic split into partitions. Each partition is copied to three brokers — one leader, two followers — and read by one consumer in the group. Break brokers and consumers, change acks and commit order, and see ordering, lag, data loss, duplicates, retention and replay.
Try it
- Producers — key = user id — healthy — 2/s · acks=all
- Partition 0 — leader B1 · 3/3 in sync — healthy — lag 0
- Partition 1 — leader B2 · 3/3 in sync — healthy — lag 3
- Partition 2 — leader B3 · 3/3 in sync — healthy — lag 1
- Consumer C1 — reads P0, P2 — healthy — 0 processed
- Consumer C2 — reads P1 — healthy — 2 processed
- Dead-letter queue — 0 messages parked — healthy
- Asynchronous
- Event / message
- Poison message
Producer
Consumers
Cluster
Numbers add up:sent 9 = waiting 0 + awaiting ack 3 + acknowledged 6 + failed 0; every partition: oldest kept ≤ committed ≤ high watermark ≤ end; one consumer per partitionThe lab checks this sum as it runs, so a counting mistake would show here.
Controls
Follow a request
Pause to pick a request that is on screen.
Show data table
| Time | Lag |
|---|---|
| 1s | 0 |
| 1s | 1 |
| 2s | 3 |
| 2s | 2 |
| 3s | 2 |
| 3s | 4 |
Show data table
| Time | Sent by producers | Processed |
|---|---|---|
| 1s | 4 | 0 |
| 1s | 2 | 0 |
| 2s | 0 | 0 |
| 2s | 2 | 2 |
| 3s | 4 | 2 |
| 3s | 6 | 0 |
Show data table
| Time | Requests/s |
|---|---|
| 1s | 4 |
| 1s | 2 |
| 2s | 0 |
| 2s | 2 |
| 3s | 4 |
| 3s | 6 |
Show data table
| Time | p99 |
|---|---|
| 1s | 0 |
| 1s | 627 |
| 2s | 710 |
| 2s | 710 |
| 3s | 710 |
| 3s | 824 |
Brokers & replicas
| Broker | P0 | P1 | P2 | Action |
|---|---|---|---|---|
| B1up | Leader | Follower | Follower | |
| B2up | Follower | Leader | Follower | |
| B3up | Follower | Follower | Leader |
“has N” is how many messages that copy holds. The in-sync replicas (ISR) are the copies that are caught up; only they can become leader.
Partition logs
- 0u3
- 1u3
- 2u6
- 3u3
- 4u3
- 5u3
- 6u6
- 0u5
Faded cells are committed. The outlined cell is next for the consumer. Dashed cells are above the high watermark: written to the leader but not yet on every in-sync replica, so consumers cannot see them. Cells marked "gone" were removed by compaction, because a newer message has the same key.
What just happened
Nothing yet. Start traffic or run an experiment.
Compare two acks settings through the same leader crash
Both sides produce the same messages, with the same keys, at the same moments. From 10 s, the first time partition 0's leader holds messages its followers have not copied, that leader's broker dies on both sides at once. Only the acks setting differs, so any gap comes from acks. Both sides start with 20 seconds already run.
The producer waits for the partition leader only. A write the followers have not copied dies with the leader.
The producer waits until every in-sync replica has the write. Slower, and a confirmed write survives the leader dying.
- Producers — 4/s · acks=1 — healthy
- Partition 0 — leader B2 — DEGRADED — 2/3 in sync · lag 4
- Partition 1 — leader B2 — DEGRADED — 2/3 in sync · lag 22
- Partition 2 — leader B3 — DEGRADED — 2/3 in sync · lag 14
- Consumer C1 — reads P0, P2 — healthy — 21 processed
- Consumer C2 — reads P1 — healthy — 22 processed
- Producers — 4/s · acks=all — healthy
- Partition 0 — leader B2 — DEGRADED — 2/3 in sync · lag 5
- Partition 1 — leader B2 — DEGRADED — 2/3 in sync · lag 22
- Partition 2 — leader B3 — DEGRADED — 2/3 in sync · lag 14
- Consumer C1 — reads P0, P2 — healthy — 21 processed
- Consumer C2 — reads P1 — healthy — 22 processed
- Asynchronous
- A message, named after its key
Each side draws only a few messages at a time, so the boxes stay easy to follow. The table counts every message. The leader crashed at 10.1 s on both sides.
| Measure | Side 1 · acks=1 | Side 2 · acks=all | Gap |
|---|---|---|---|
| Messages produced | 86 | 86 | Same messages |
| Confirmed to the producer | 84 | 84 | Same |
| Producer wait for a confirm, p50 | 337 ms | 735 ms | acks=1 lower by 399 ms |
| Confirmed, then lost | 1 | 0 | acks=all lower by 1 |
Changing a setting starts both sides again, so the numbers always describe one setup from its start. 3 brokers hold 3 copies of each partition. A crashed broker stays down, so a second crash leaves fewer copies. "Confirmed, then lost" counts messages the producer was told were saved that are no longer in any log.
What this model simplifies
- Three brokers, replication factor 3, and min.insync.replicas = 2 (the broker default is 1; 2 with 3 replicas is a common production choice). A controller notices a dead broker after 1.5 s.
- Followers are dropped from the in-sync set only when their broker dies. Real Kafka also drops a follower that falls too far behind (replica.lag.time.max.ms).
- Eager rebalancing hands partitions out round-robin and pauses the whole group. Cooperative rebalancing here moves only what must move in one step; real Kafka takes two rounds, and newer versions have a new group protocol.
- Offsets are committed after every message. Real consumers commit in batches, which widens the window for duplicates after a crash.
- Exactly-once transactions here cover one result and its offset. Real Kafka transactions write to output topics, which readers see only with read_committed. For effects outside Kafka, such as an email, you still need an idempotent consumer.
- Failed messages are retried in place, blocking the partition. Many teams publish them to a retry topic with a delay instead.
- Retention is by time only and deletes single messages. Real Kafka deletes whole log segments by time or size. Compaction here marks single entries removed once they are 3 s old; real Kafka cleans closed segments in the background, and deleting a key with an empty message (a tombstone) is not shown.