What is the role of a Partition in Kafka?
Instruction: Describe what a partition is within the context of Kafka, its purpose, and how it affects data storage and retrieval.
Updated
Official answer
A partition is one ordered log within a Kafka topic. Records are appended with increasing partition-local offsets. An offset identifies a position in that partition, not a global topic position; visible offsets can contain gaps after compaction or transactions.
Partitions provide units of storage placement and parallel work. Brokers host their replicas, and a leader coordinates writes for each partition. Replication is what supplies redundant copies; simply splitting a topic into more partitions does not make each copy durable.
Producers select a partition through an explicit choice or a partitioning policy, often based on a key. Keeping one entity's events in one partition supports per-entity order. Consumers in a standard subscribing group divide partitions among members, while different groups can read the same retained data independently.
Consumers track progress separately through committed offsets. Reading or committing a record does not delete it from the topic. Retention and cleanup policies govern removal, and replay is possible only while the required data remains available.
Partition count involves tradeoffs: more partitions can allow more parallelism but add metadata, files, replication and recovery work, and may reduce batch efficiency. A hot key still maps to one partition. Adding partitions can change key routing without moving historical records; adding brokers requires appropriate replica placement/reassignment to use their capacity.
Partitions do not themselves provide global ordering or exactly-once business processing. Those require additional application or transactional design.
Kafka introduction, partition operations, consumer positions
Related Questions
-
easy
-
easy
-
easy
-
easy
-
medium
-
medium