01 / 05

What is a Kafka partition and why is it important?

Difficulty: 2/10
Partitioning and ordering

A partition is an ordered, append-only log that is the unit of ordering, parallelism and replication

A topic is a logical name; the data physically lives in partitions. Each partition is an append-only, immutable log stored on a broker as segment files, and every record in it gets a sequential offset starting at 0. Offsets are only meaningful within a partition, so the real identity of a record is topic, partition, offset. Partitions matter because three separate properties hang off them.

  1. 1

    Ordering: Kafka guarantees order only within a partition. Two records in different partitions have no defined relative order.

  2. 2

    Parallelism: within one consumer group, each partition is assigned to at most one consumer at a time. So the partition count is the ceiling on useful consumers in a group. Partitions also spread write and read load across brokers.

  3. 3

    Replication and failure handling: replication is configured per partition. Each partition has one leader that serves reads and writes and follower replicas that stay in sync (the ISR). When a broker dies, leadership moves partition by partition, not topic by topic.

javascript

The trade-off is that more partitions give more parallelism but cost more: more open file handles, more replication traffic, more producer batch memory, longer leader elections and slower rebalances. Common mistakes I see: assuming a topic has a single global order, adding consumers beyond the partition count and expecting more throughput (the extras sit idle), and forgetting that you can increase partitions but never decrease them. Adding partitions later also changes the key-to-partition mapping for keyed data. Version note: very high partition counts per broker were a real problem in ZooKeeper-based clusters; KRaft (the only mode from Kafka 4.0) raises that ceiling, but I would still verify limits against my version and hardware.

Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.