1.Topics, partitions, offsets and consumer groups
A 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.
Key features
- Topic: a named category/stream of messages, e.g. "order-events"
- Partition: a topic is split into one or more partitions, each an independently ordered, append-only log
- Offset: a message's position within its partition — strictly increasing, unique per partition
- Ordering: guaranteed within a partition only — two messages in different partitions have no guaranteed relative order
- Consumer group: a set of consumers that split a topic's partitions among themselves — each partition is read by exactly one consumer in the group at any time
- Retention: Kafka keeps messages for a configured period (or size limit) regardless of whether they've been consumed — unlike a traditional queue, reading a message does not delete it
Kafka's core vocabulary
- 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)
Command
topic "orders" → partition 0: [msg0, msg1, msg2, ...]
→ partition 1: [msg0, msg1, msg2, ...]
→ partition 2: [msg0, msg1, msg2, ...]
consumer group "billing":
consumer A ← partition 0
consumer B ← partition 1, partition 2A 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.