Apache Kafka Tutorial 0/111 lessons ~6 min read Lesson 8
Partitions
What is Partitions?
Course progress0%
Focus
9 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
What is Partitions? Partitions are ordered append-only logs.
Understanding the topic
What happens — Partitions:
- Each partition is an ordered append-only log.
- Producer key picks the partition.
- Ordering is guaranteed within one partition only.
- More partitions enable more consumer parallelism.
| Term | Description |
|---|---|
| Partition | Ordered log segment inside a topic. |
| Partition key | Hash input that routes related records together. |
| Leader | Broker handling reads/writes for this partition. |
| Hot partition | Skew when one key dominates traffic. |
Visual explanation
Pipeline view:
text
Producer↓Topic partition log↓Consumer group A↓Consumer group BReplay is possible because records are retained
Step-by-step explanation
- Key record — Producer sets key or round-robin.
- Hash — partition = hash(key) % count.
- Append — Leader writes to log segment.
- Assign — One consumer per partition in group.
Informative example
Example:
bash
kafka-topics --bootstrap-server localhost:9092 --create --topic partitions --partitions 6 --replication-factor 3kafka-console-producer --bootstrap-server localhost:9092 --topic partitionskafka-console-consumer --bootstrap-server localhost:9092 --topic partitions --from-beginningkafka-consumer-groups --bootstrap-server localhost:9092 --describe --group partitions-service
Execution workflow
1Partitions workflow
1 / 4Key record
Producer sets key or round-robin.
Best practices
- Design events around business facts: OrderCreated, PaymentAuthorized, InventoryReserved.
- Pick keys based on ordering and load distribution.
- Document owner, retention, schema, partitions, and consumers for every topic.
- Assume duplicate delivery and build idempotent consumers early.
Common mistakes
- Expecting global ordering across a topic.
- Creating one partition because local demos work.
- Skipping schema governance until multiple teams deploy independently.
Summary
Partitions — Start every design with event ownership, topic naming, key choice, schema contract, retention, replay plan, and monitoring.
Ready to mark this lesson complete?Track your journey across the entire course.