What is the difference between a topic and a partition in Kafka, and why does a topic need partitions at all?
Why they ask this
Reported almost word for word from Kotak and Walmart loops. It checks whether you know that the partition, not the topic, is the unit of ordering, parallelism, replication and storage — every later answer about lag, ordering and rebalancing depends on it.
Say this
A topic is the name of a stream; a partition is one ordered, append-only log that physically holds part of it, with its own offsets, leader and replicas. Partitions exist so one topic can be written and read in parallel across brokers and consumers — and a partition is also the only scope in which Kafka promises order.
The reasoning
A **topic** is a logical category that producers write to and consumers subscribe to. It holds no data itself. The data lives in its **partitions**: each one is an ordered, immutable sequence of records, stored as segment files on the broker that leads it, with every record numbered by an **offset**. Offset 42 means nothing without a partition — partition 3 and partition 5 of the same topic both have an offset 42.
Partitions exist because a single log caps everything at one machine. One log means one leader broker taking every write and, within a consumer group, one consumer reading everything. Split the topic into 12 partitions and the leaders spread across brokers, and up to 12 consumers in a group can read at once. **The partition count is the ceiling on consumer parallelism** in a classic consumer group, because a partition is read by at most one member of the group.
The partition is also the unit of **replication** — each has its own leader, followers and in-sync replica set — and of **ordering**. Records within a partition are read in the order they were appended; across partitions there is no ordering relationship at all. That is why the record key matters: it decides the partition, and so it decides which records are ordered relative to each other.
Partitions are not free. Each one is open segment and index files on every replica, replication traffic, cluster metadata and a leader to move when a broker fails. And the count only goes up: you can add partitions to a topic but never remove them.
The answer most people give
"A topic is like a table and partitions are its rows split up for storage." It makes partitions sound like an implementation detail. They are the contract: ordering, parallelism and replication are all per partition, and an answer that stops at storage cannot explain why a third consumer on a 2-partition topic sits idle.
They’ll ask next
Can you reduce a topic from 12 partitions to 6? If not, how would you get there?
Reported in 2 interview write-ups
