Three nouns carry almost all of Kafka's semantics. Get these precise and the rest of the system stops being surprising.
Topic: a name, not a thing
A topic is a logical category — orders, page-views, payment-events. It stores nothing itself. It is a label over a set of partitions.
Partition: the actual log
A partition is an ordered, immutable, append-only sequence of records stored on disk. Writes go on the end. Nothing is ever inserted in the middle.
partition 0: [0][1][2][3][4][5][6] <── append here
▲
log end
partition 1: [0][1][2][3] <── append here
partition 2: [0][1][2][3][4][5][6][7][8]
Offset: position within one partition
An offset is a monotonically increasing integer identifying a record's position inside a single partition. Offset 5 in partition 0 is unrelated to offset 5 in partition 1. Offsets are not global, and they are not timestamps.
A record's full address is therefore (topic, partition, offset).
The rule that bites everyone
Kafka guarantees ordering within a partition. It guarantees nothing about ordering across partitions of the same topic.
This is not a limitation to be worked around; it is the price of horizontal scale. Ordering across partitions would require global coordination, which is exactly what Kafka avoids in order to go fast.
The practical consequence: if two events must be processed in order relative to each other, they must land in the same partition. Events for different entities can safely be spread out. So "order events must be ordered" is usually the wrong requirement — the right one is "events for a given order must be ordered", which is achievable.
Wanted: order-42 Created → Paid → Shipped (in that order)
Same partition: p1: [Created][Paid][Shipped] ✓ safe
Different partitions: p0: [Paid] p1: [Created] p2: [Shipped]
consumers may see Paid before Created ✗
Module 2 covers how message keys let you control this.
Why more than one partition
Partitions are the unit of:
| Concern | How partitions govern it |
|---|---|
| Parallelism | One partition is read by at most one consumer in a group, so partition count caps consumer concurrency |
| Ordering | Ordering is guaranteed only inside a partition |
| Storage | A partition lives on specific brokers, so partitions spread data across the cluster |
Choosing partition count
There is no universal number, but there is a reliable method: estimate target throughput, measure what a single partition sustains in your environment with your record sizes and processing cost, then divide and add headroom.
Two asymmetric costs shape the decision:
- Too few partitions caps your throughput and your consumer parallelism, and increasing later is disruptive (see below).
- Too many partitions means more open file handles, more replication work, more metadata, and slower leader elections and rebalances.
Over-provisioning slightly is the lesser evil, but "1000 partitions just in case" is a real operational cost.
Adding partitions is not free
You can increase partition count on an existing topic. You cannot decrease it. And the increase has a consequence people discover in production:
Kafka's default partitioner maps a keyed record via a hash of the key modulo the partition count. Change the partition count and that mapping changes.
key "user-7" hashed → 91
partitions = 3 → 91 % 3 = 1 (partition 1)
partitions = 4 → 91 % 4 = 3 (partition 3)
Old events for user-7 sit in partition 1; new ones go to partition 3. Two consumers now process that user's history concurrently and out of order. Adding partitions silently breaks per-key ordering for all existing keys.
Mitigations, in order of preference: size partitions adequately up front; or create a new topic with the desired partition count and migrate consumers; or use a custom partitioner with a stable mapping that does not depend on partition count.
Exercise: A topic shipments has 6 partitions and is keyed by shipment_id. Traffic doubles and someone proposes bumping it to 12 partitions during a quiet window. Explain what breaks for shipments already in flight, and describe a migration that preserves per-shipment ordering.