Kafka Quick Recap
Producer โ Topic โ Partitions โ Consumer Group โ Consumers 1. Producer Publishes messages/records to Kafka. Can publish to one or multiple topics. Producer doesn't own partitions. Kafkaโฆ
Producer
โ
Topic
โ
Partitions
โ
Consumer Group
โ
Consumers
1. Producer
- Publishes messages/records to Kafka.
- Can publish to one or multiple topics.
- Producer doesn’t own partitions.
- Kafka decides which partition receives the record.
Producer โ Topic A
โ Topic B
โ Topic C
2. Topic
- Logical category/name for messages.
- A topic contains one or more partitions.
order-events
โโโ P0
โโโ P1
โโโ P2
3. Partition
- Actual place where Kafka stores records.
- Records have offsets within a partition.
- Ordering is guaranteed within a partition, not across the whole topic.
P0 โ Offset 0, 1, 2, 3, 4...
4. Offset
- Position of a record inside a partition.
- Offset starts from
0. Current Offsetusually represents the next position to read.
Records: 0 1 2 3 4 5
Next: 6
So if:
Current Offset = 6
Log-End Offset = 6
Lag = 0
the consumer is caught up.
5. Consumer
- Reads records from Kafka.
- Can consume from multiple topics.
- Kafka assigns partitions to consumers.
Consumer โ P0
โ P1
6. Consumer Group
- A team of consumers working together.
- A consumer group can consume from multiple topics.
- Within the same consumer group:
One partition โ only one consumer at a time.
Example:
inventory-group
Consumer 1 โ P0, P1
Consumer 2 โ P2
7. Multiple Consumer Groups
Different groups can consume the same topic/partition independently.
order-events
/ | \
P0 P1 P2
โ โ โ
โโโโโโโโโโดโโโโโโโโดโโโโโโโโดโโโโโโโโโ
โ โ
inventory-group analytics-group
โ โ
Consumers Consumers
8. Scaling Rule โญ
3 partitions + 1 consumer
โ consumer handles all 3
3 partitions + 3 consumers
โ each can handle 1
3 partitions + 5 consumers
โ 2 consumers will be idle
Maximum useful parallelism within one consumer group = number of partitions.
The 7 things to remember
| Concept | Remember |
|---|---|
| Producer | Publishes records |
| Topic | Category/logical stream |
| Partition | Stores ordered records |
| Offset | Record position in partition |
| Consumer | Reads records |
| Consumer Group | Consumers working together |
| Lag | Records still waiting to be consumed |
โญ One-line mental model
Producer publishes โ Topic contains partitions โ Partitions contain records with offsets โ Consumer Groups consume those partitions โ Consumers are assigned partitions.