Unit 2 of 15 · about 4 hours · explain

Partitions, per-partition ordering, replication and high-watermark visibility

Partitioning buys throughput by giving up global order, and replication buys survival by hiding uncommitted records. Every routing key and every read after a failover depends on this boundary.

You'll be able to

  • Explain per-partition ordering and how a partition key routes all events of one entity to the same partition.
  • Explain leader, followers and in-sync replicas, and why only committed offsets below the high watermark are visible to consumers.
  • State which writes survive a leader loss under acks=all with min.insync.replicas set, and which are refused instead.

Covers

Partitions and per-partition orderingReplication and high-watermark visibility
1

Read

In this order, only the parts listed

0 of 2 done

  1. Partitions and per-partition orderingDDIA 2e - Chapters 11 to 13 Batch and Stream Processing

    Chapter 12, Log-Based Message Brokers (pp. 496 to 497): Figure 12-3, offsets within a partition, no ordering across partitions, routing by partition key such as user ID

  2. Replication, ISR and durability guaranteesApache Kafka 4.3 - Design, Log, Rebalance and Transaction Protocols

    Replication; Replicated Logs: Quorums, ISRs, and State Machines; Availability and Durability Guarantees (acks with min.insync.replicas; committed writes safe while one in-sync replica lives); Unclean leader election

2

Focus on

  • A partition is the unit of ordering and of parallelism: more partitions raise throughput but also the number of independent sequences.
  • All events that need a fixed relative order must share a partition key. Key by entity ID, not by timestamp.
  • Followers pull like consumers, and the leader commits a write only after all in-sync replicas receive it.
  • The high watermark marks the end of the committed prefix: consumers read only offsets below it, never up to the log end offset, so uncommitted tail records stay invisible.
Common mistakes · 3
  • Reading uncommitted tail records. A record the leader holds but has not committed can vanish in a failover.
  • Enabling unclean leader election for availability and still claiming no loss. An out-of-sync replica elected leader drops records the old leader had committed.
  • Assuming partition count can be lowered later. Kafka supports only increasing partitions per topic, which changes the key-to-partition mapping.
3

Try it yourself

Closed-book, before checking anything

Closed-book, draw one partition with a leader and two followers, mark the log end offset and the high watermark after a write reaches the leader and one follower, and state which acks values would have returned success.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Two requests from one user are handled by different web servers. How do their events keep a fixed relative order?Answer

    Route both by the user ID as partition key so they land in the same partition, which is totally ordered.

  2. 2.A write reaches the leader only. Which acks settings report success, and can a consumer read the record?Answer

    acks=1 and acks=0 report success; acks=all does not. No consumer can read it yet because it is still above the high watermark.

  3. 3.With min.insync.replicas=2, one follower lags out of the ISR and then the leader dies. What happens to committed writes and to new acks=all writes?Answer

    Committed writes are safe while one in-sync replica lives. New acks=all writes are refused with an error until the ISR recovers; nothing is silently lost.

  4. 4.Unclean leader election is enabled, all in-sync replicas die, and an out-of-sync replica is elected. What breaks?Answer

    Records committed on the dead replicas but missing on the new leader are lost, and consumers can see gaps. Availability is preserved at the cost of the durability contract.

You're done when

You can trace a write from leader append through ISR acknowledgement to consumer visibility, and predict the outcome of each failover case above.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 16 more in the section
  • DDIA 2e - Chapters 11 to 13 Batch and Stream ProcessingMartin Kleppmann and Chris Riccomini · primary

    Read batch processing, stream processing and the streaming-systems philosophy in order. For every guarantee, mark the source position, operator state, output effect and recovery boundary it actually covers.

  • Apache Kafka 4.3 - Design, Log, Rebalance and Transaction ProtocolsApache Kafka · required

    Read the 4.3 design page (replication and in-sync replicas, acknowledgements and min.insync.replicas, delivery semantics, idempotence and transactions, the consumer, log compaction), the log implementation page, and the consumer rebalance protocol and transaction protocol pages (https://kafka.apache.org/43/operations/). Kafka 4.0 removed ZooKeeper. Run experiments in the apache/kafka:4.3.1 image and compare each contract with your mini log.

Also in this section