Build your own mini Kafka · Stage 1 of 8
ApiVersions over TCP
Every Kafka client's first move is an ApiVersions request: "which APIs and versions do you speak?" Your broker must answer it correctly or no real client will proceed.
The starter already length-frames requests/responses and prints
LISTENING <host>:<port>. Implement dispatch(request_bytes):
- parse the request header (api_key, api_version, correlation_id, client_id),
- for ApiVersions (api_key 18), return a response the official
kafka-broker-api-versions.shand librdkafka accept.
Advertise at least ApiVersions(18), Metadata(3), Produce(0), Fetch(1) — you will implement those in later stages, but clients negotiate against this table now.
Tests: a raw-socket decode of your ApiVersions v3 response, and the official CLI tool connecting to you.
Hints
Hint 1
A request starts with a 4-byte length, then the header: api_key int16, api_version int16, correlation_id int32, client_id (nullable string, 2-byte length). ApiVersions is api_key 18.
Hint 2
The ApiVersions RESPONSE header is just the correlation_id (int32) with NO tagged-field section, even for v3 — this is a well-known quirk. The body is: error_code int16, then a COMPACT array of {api_key int16, min int16, max int16, tagged_fields} for v3, then throttle_time_ms int32 and tagged_fields.
Hint 3
Advertise at least ApiVersions(18), Metadata(3), Produce(0) and Fetch(1) with version ranges your later stages will implement. kafka-broker-api-versions.sh prints the table it parses, so start there.
uv run de start KFK-BYO/01-apiversions-tcp
uv run de test