Integration / Apache Kafka Interview questions
What is a partition in Kafka?
A partition is an ordered, immutable subdivision of a topic's log — each partition is its own independent sequence of records, and a topic with multiple partitions is really multiple parallel logs sharing one topic name.
Ordering is guaranteed within a partition (records are appended in the order they're written and read back in that same order), but there's no guaranteed ordering across different partitions of the same topic. This is the mechanism that gives Kafka horizontal scalability: partitions can be spread across different brokers, and different consumers in a group can each own a different partition, reading and processing in parallel.
kafka-topics.sh --describe --topic orders --bootstrap-server localhost:9092 # Topic: orders PartitionCount: 3 ReplicationFactor: 2
A record's partition is chosen either explicitly by the producer, or derived from the record's key via a hashing partitioner, which is what guarantees all records sharing the same key land in the same partition and therefore stay ordered relative to each other.
More Related questions...