LESSON 02 · The partitioned log

Treat the log as the backbone

A partitioned log keeps records after they are read, so many consumers can move through it independently, with ordering guaranteed inside each partition.

SYSTEM VIEW

The data flow

Diagram view
Billing lag—
Search lag—

Follow order 812’s events into one partition of an orders topic, then watch two consumer groups read them at their own pace.

  1. Checkout publishes order 812’s first event, keyed by order ID. The key’s hash picks partition 3, and the record lands at its end with the next offset, 1041. Nothing before it moves.

    Partitions
    6
    Key
    order ID
    Offset
    1041

    What changed

    • 812 new at partition 3, offset 1041
    • Key 812 hashes to partition 3
  2. Order 812 is paid, then shipped. The same key hashes to the same partition, so those events land in order at 1042 and 1043. Order 813 hashes to partition 1 and gets that partition’s next offset.

    What changed

    • 812 paid at 1042, 812 sent at 1043
    • 813 new at partition 1, offset 1105
    • Each partition counts its own offsets
  3. A billing group of 6 consumers takes one partition each; a seventh would sit idle. Billing’s consumer for partition 3 reads 1041 and commits, so its offset moves on to 1042. The record stays in the log.

    Consumers
    6, one per partition
    A seventh
    idle

    What changed

    • Billing group, a consumer on each partition
    • Billing commits offset 1042
    • 1041 stays in the log
  4. A search-indexing group reads the same records with its own committed offset. It indexes 1041 and 1042 while Billing’s position stays where it was: reading a log takes nothing out of it.

    What changed

    • Search indexer, its own group
    • Search commits offset 1043
    • Billing still at 1042
  5. Billing reads partition 3 in order, so 812 is paid before it ships. Partition 1 has its own consumer, and 813’s event can be read before or after 812’s. Choose the key whose events must stay in order.

    What changed

    • 812 paid before 812 sent
    • 813 and 812 can interleave
  6. Billing’s consumer reads 1043 and records the shipment, then crashes before committing. Its replacement starts from the last committed offset, 1043, so that work runs again before it commits 1044. Its effect must tolerate a repeat.

    What changed

    • Consumer crashes before its commit
    • Replacement starts at 1043, then commits 1044
    • 812 sent is processed twice

Space plays · ← → step · Home resets

THE IDEA

How it works

A message queue typically removes a job once a worker finishes it. A log keeps records, in order, until a retention limit passes, which lets many independent readers share one stream and replay it. In Kafka, a topic is split into partitions. Each partition is an append-only sequence, and each record gets an offset, its position in that partition. A producer’s key is hashed to choose a partition, so records with the same key land together.

A consumer group is a set of consumers sharing a topic’s work. Kafka assigns each partition to one member of the group at a time, and the group commits how far it has read. For example, an orders topic has 6 partitions and is keyed by order ID. Events for order 812 all go to partition 3, at offsets 1041, 1042, and 1043, and are read in that order. A billing group with 6 consumers gives each one partition, and a seventh consumer sits idle. A search-indexing group reads the same records with its own offsets, without affecting billing’s position.

Order holds within a partition, not across a topic, so orders 812 and 813 can interleave if they land on different partitions. Partition count caps a group’s parallelism, and one slow record delays everything behind it in that partition. Adding partitions changes where a key hashes, so an order’s new events can separate from its older ones. When a consumer dies, another member resumes from the last committed offset, so work done but not yet committed runs again.

DECISION POINT

An accounts topic has 8 partitions keyed by account ID, and consumers apply balance changes in order. Lag is growing, so a colleague proposes raising it to 16 partitions tonight and doubling the consumers. What do you check before agreeing?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Records stay after being read, so each group tracks its own offset and can replay.
  • Ordering holds per partition, so choose the key whose records must stay in order.
  • A group cannot use more active consumers than it has partitions.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
ApplyQUESTION 01

A topic has 4 partitions. A consumer group scales from 4 consumers to 6. What happens?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.