Topics, partitions, offsets and consumer groups
coreadvancedA Kafka topic is a named stream of messages, physically split into partitions for parallelism — each partition is an ordered, append-only log with its own offset counter. Kafka only guarantees message order within a single partition, never across partitions of the same topic. Consumer groups let multiple consumers split a topic's partitions between them, each partition read by exactly one consumer in the group at a time.
Think of it as
A topic is a multi-lane highway, and each partition is one lane — cars (messages) in the same lane keep their relative order, but a car in lane 2 has no guaranteed relationship to a car in lane 5's position. A consumer group is a team of toll workers, one assigned per lane at a time — more workers than lanes just means some workers stand idle with nothing to do.
What we're doing: Show why ordering only holds within a partition, using an order-events topic keyed by order_id.
- 6
- Keying by order_id is what makes per-order ordering possible — same key always routes to the same partition.
- 13
- This is the actual scope of the ordering guarantee — it never extends across partitions, even within the same topic.
Why this works: Choosing the right partition key is what determines what ordering guarantee a consumer actually gets — a design that needs strict ordering for a given entity (like one order's lifecycle) has to key on that entity's ID, not leave partitioning to a round robin.
Assuming a Kafka topic guarantees global message order
Wrong
Better
What you see: A consumer processes a "shipped" event for one order before the "created" event for a completely different order, and a team is surprised — because global ordering across a whole topic was never actually a guarantee Kafka made, only per-partition ordering was.
Why: Kafka scales partitions in parallel specifically by giving up a global ordering guarantee — the trade is deliberate: partitioning is what allows a topic's throughput to scale past a single log's write speed, at the cost of only guaranteeing order within each individual partition.
- Topic: orders — 3 partitions, each an ordered log
- Partition 0
- Partition 1
- Partition 2
- Consumer group: billing — 1 partition per consumer, at a time
- Consumer A
- Consumer B (×2)
Kafka's core vocabulary
Remember: A topic's partitions are independently ordered logs — Kafka guarantees order within a partition, never across partitions. Consumer groups split partitions among consumers, one partition per consumer at a time, so parallelism is capped by partition count.
See also: delivery guarantees · replayable event logs · partitioning as a decision

