Build your own mini Kafka · Stage 5 of 8
Metadata + multiple topics & partitions
Make the broker multi-topic and multi-partition.
- Metadata (api 3) lists each topic's partitions, with this broker as leader and sole replica/ISR. Unknown requested topics are auto-created.
- Key your logs by
(topic, partition); a Produce/Fetch names the partition. - CreateTopics (api 19) lets
AdminClient.create_topicsset the partition count — store it and report it in Metadata.
Tests: two topics stay isolated; producing to partition 2 of a 3-partition topic is readable only on partition 2; per-partition end offsets are independent.
Hints
Hint 1
Metadata (api 3) must list every requested topic with its partitions, each partition naming this broker as leader and sole replica/isr. When the client asks for an unknown topic, auto-create it (one partition) so a producer can proceed.
Hint 2
A Produce/Fetch request names a partition index; key your logs by (topic, partition) and create as many partitions as the highest index you see (or the count a CreateTopics request asked for).
Hint 3
Implement CreateTopics (api 19, flexible from v5) so AdminClient.create_topics can set the partition count; store it and report it back in Metadata.
uv run de start KFK-BYO/05-metadata-topics-partitions
uv run de test