Discuss the trade-offs between using smaller vs. larger partitions in a Kafka topic.
Instruction: Explain how the choice of partition size impacts system performance, scalability, and maintenance.
Updated
Official answer
Clarify what “smaller partitions” means. Partition count, retained bytes per partition and segment-file size are different choices. Lowering retention or segment size does not create additional partition ownership slots.
For a fixed total workload, distributing data across more partitions can expose more standard consumer-group parallelism and reduce the amount moved for one partition. It only helps if routing distributes work and brokers, consumers and destinations have capacity. A hot entity that must remain ordered can still dominate one partition.
More partitions add replica files, metadata, fetch/replication work and recovery coordination. At a fixed traffic rate they can also produce smaller batches. Fewer partitions reduce those overheads but limit ownership parallelism and can make individual replica movement or restoration larger.
Segment size controls files within a partition. Smaller segments provide finer retention/cleaning granularity with more files; larger segments reduce file count while making cleanup coarser. Segment rolling is not the same operation as adding a partition, and large messages have their own limits.
For example, dividing a nominal 800 GiB evenly among eight partitions gives 100 GiB each; sixteen gives 50 GiB each before replication. Actual skew, retention and overhead matter, and increasing an existing topic's count does not redistribute its historical data this way automatically.
Choose the layout from measured throughput, key distribution, recovery time and operating limits. Plan key-remapping/order consequences before expanding partitions and use a new topic/migration when a smaller count is required.