Skip to content

Commit 68c3110

Browse files
committed
feat: add stage descriptions for Produce API extension
1 parent 429d75c commit 68c3110

File tree

7 files changed

+250
-0
lines changed

7 files changed

+250
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
In this stage, you'll add an entry for the `Produce` API to the APIVersions response.
2+
3+
## APIVersions
4+
5+
Your Kafka implementation should include the Produce API (key=0) in the ApiVersions response before implementing produce functionality. This would let the client know that the broker supports the Produce API.
6+
7+
## Tests
8+
9+
The tester will execute your program like this:
10+
11+
```bash
12+
./your_program.sh /tmp/server.properties
13+
```
14+
15+
It'll then connect to your server on port 9092 and send a valid `APIVersions` (v4) request.
16+
17+
The tester will validate that:
18+
19+
- The first 4 bytes of your response (the "message length") are valid.
20+
- The correlation ID in the response header matches the correlation ID in the request header.
21+
- The error code in the response body is `0` (No Error).
22+
- The response body contains at least one entry for the API key `0` (Produce).
23+
- The `MaxVersion` for the Produce API is at least 11.
24+
25+
## Notes
26+
27+
- You don't have to implement support for the `Produce` request in this stage. We'll get to this in later stages.
28+
- You'll still need to include the entry for `APIVersions` in your response to pass the previous stage.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
In this stage, you'll add support for handling Produce requests to non-existent topics with proper error responses.
2+
3+
## Handling Non-Existent Topics
4+
5+
Your Kafka implementation should validate topic existence and return appropriate error codes when a client tries to produce to a non-existent topic. Kafka stores metadata about topics in the `__cluster_metadata` topic. To check if a topic exists or not, you'll need to read the `__cluster_metadata` topic's log file, located at `/tmp/kraft-combined-logs/__cluster_metadata-0/00000000000000000000.log`. If the topic exists, the topic will have a directory with all the data required for it to operate at `<log-dir>/<topic-name>-<partition-index>`.
6+
TODO: Do we need to explain the TOPIC_RECORD record in the `__cluster_metadata` log.
7+
8+
## Tests
9+
10+
The tester will execute your program like this:
11+
12+
```bash
13+
./your_program.sh /tmp/server.properties
14+
```
15+
16+
It'll then connect to your server on port 9092 and send a `Produce` (v11) request to a non-existent topic.
17+
18+
The tester will validate that:
19+
20+
- The first 4 bytes of your response (the "message length") are valid.
21+
- The correlation ID in the response header matches the correlation ID in the request header.
22+
- The error code in the response body is `3` (UNKNOWN_TOPIC_OR_PARTITION).
23+
- The `throttle_time_ms` field in the response is `0`.
24+
- The `name` field in the topic response inside response should correspond to the topic name in the request.
25+
- The `partition` field in the partition response inside topic response should correspond to the partition in the request.
26+
- The `offset` field in the partition response inside topic response should be `-1`.
27+
- The `timestamp` field in the partition response inside topic response should be `-1`.
28+
- The `log start offset` field in the partition response inside topic response should be `-1`.
29+
30+
## Notes
31+
32+
- You'll need to parse the `Produce` request in this stage to get the topic name and partition to send in the response.
33+
- The official docs for the `Produce` request can be found [here](https://kafka.apache.org/protocol.html#The_Messages_Produce). Make sure to scroll down to the "Produce Response (Version: 11)" section.
34+
- The official Kafka docs don't cover the structure of records inside the `__cluster_metadata` topic, but you can find the definitions in the Kafka source code [here](https://github.com/apache/kafka/tree/5b3027dfcbcb62d169d4b4421260226e620459af/metadata/src/main/resources/common/metadata).
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
In this stage, you'll add support for handling Produce requests to invalid partitions for known topics with proper error responses.
2+
3+
## Handling Invalid Partitions
4+
5+
Your Kafka implementation should validate that partition indices exist for known topics and return appropriate errors for invalid partitions. Kafka stores metadata about partitions in the `__cluster_metadata` topic. To check if a partition exists or not, you'll need to read the `__cluster_metadata` topic's log file, located at `/tmp/kraft-combined-logs/__cluster_metadata-0/00000000000000000000.log`. If the partition exists, the partition will have a directory with all the data required for it to operate at `<log-dir>/<topic-name>-<partition-index>`.
6+
TODO: Do we need to explain the PARTITION_RECORD record in the `__cluster_metadata` log.
7+
8+
## Tests
9+
10+
The tester will execute your program like this:
11+
12+
```bash
13+
./your_program.sh /tmp/server.properties
14+
```
15+
16+
It'll then connect to your server on port 9092 and send a `Produce` (v11) request to a known topic with an invalid partition.
17+
18+
The tester will validate that:
19+
20+
- The first 4 bytes of your response (the "message length") are valid.
21+
- The correlation ID in the response header matches the correlation ID in the request header.
22+
- The error code in the response body is `3` (UNKNOWN_TOPIC_OR_PARTITION).
23+
- The `throttle_time_ms` field in the response is `0`.
24+
- The `name` field in the topic response inside response should correspond to the topic name in the request.
25+
- The `partition` field in the partition response inside topic response should correspond to the partition in the request.
26+
- The `offset` field in the partition response inside topic response should be `-1`.
27+
- The `timestamp` field in the partition response inside topic response should be `-1`.
28+
- The `log start offset` field in the partition response inside topic response should be `-1`.
29+
30+
## Notes
31+
32+
- The official docs for the `Produce` request can be found [here](https://kafka.apache.org/protocol.html#The_Messages_Produce). Make sure to scroll down to the "Produce Response (Version: 11)" section.
33+
- The official Kafka docs don't cover the structure of records inside the `__cluster_metadata` topic, but you can find the definitions in the Kafka source code [here](https://github.com/apache/kafka/tree/5b3027dfcbcb62d169d4b4421260226e620459af/metadata/src/main/resources/common/metadata).
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
In this stage, you'll add support for successfully producing a single record to a valid topic and partition.
2+
3+
## Single Record Production
4+
5+
Your Kafka implementation should accept valid Produce requests, store the record in the appropriate log file, and return successful responses with assigned offsets. The record must be persisted to the topic's log file at `<log-dir>/<topic-name>-<partition-index>/00000000000000000000.log` using Kafka's on-disk log format.
6+
7+
## Tests
8+
9+
The tester will execute your program like this:
10+
11+
```bash
12+
./your_program.sh /tmp/server.properties
13+
```
14+
15+
It'll then connect to your server on port 9092 and send multiple successive `Produce` (v11) requests to a valid topic and partition with single records as payload.
16+
17+
The tester will validate that:
18+
19+
- The first 4 bytes of your response (the "message length") are valid.
20+
- The correlation ID in the response header matches the correlation ID in the request header.
21+
- The error code in the response body is `0` (NO_ERROR).
22+
- The `throttle_time_ms` field in the response is `0`.
23+
- The `name` field in the topic response matches the topic name in the request.
24+
- The `partition` field in the partition response matches the partition in the request.
25+
- The `offset` field in the partition response contains the assigned offset to the record. (The offset is the offset of the record in the partition, not the offset of the batch. So 0 for the first record, 1 for the second record, and so on.)
26+
- The `timestamp` field in the partition response contains -1 (signifying that the timestamp is latest).
27+
- The `log_start_offset` field in the partition response is `0`.
28+
29+
The tester will also verify that the record is persisted to the appropriate log file on disk at `<log-dir>/<topic-name>-<partition-index>/00000000000000000000.log`.
30+
31+
## Notes
32+
33+
- You'll need to implement log file writing using Kafka's binary log format.
34+
- Records must be stored in RecordBatch format with proper CRC validation.
35+
- The offset assignment should start from 0 for new partitions.
36+
- The official docs for the `Produce` request can be found [here](https://kafka.apache.org/protocol.html#The_Messages_Produce).
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
In this stage, you'll add support for producing multiple records from a single request with multiple record batches in the payload.
2+
3+
## Batch Processing
4+
5+
Your Kafka implementation should handle multiple records in a single batch, assign sequential offsets, and validate the LastOffsetDelta field correctly. The RecordBatch containing multiple records must be stored atomically to the log file.
6+
7+
## Tests
8+
9+
The tester will execute your program like this:
10+
11+
```bash
12+
./your_program.sh /tmp/server.properties
13+
```
14+
15+
It'll then connect to your server on port 9092 and send a `Produce` (v11) request containing a RecordBatch with multiple records.
16+
17+
The tester will validate that:
18+
19+
- The first 4 bytes of your response (the "message length") are valid.
20+
- The correlation ID in the response header matches the correlation ID in the request header.
21+
- The error code in the response body is `0` (NO_ERROR).
22+
- The `throttle_time_ms` field in the response is `0`.
23+
- The `name` field in the topic response matches the topic name in the request.
24+
- The `partition` field in the partition response matches the partition in the request.
25+
- The `offset` field in the partition response contains the base offset for the batch.
26+
- The `timestamp` field in the partition response contains a valid timestamp.
27+
- The `log_start_offset` field in the partition response is correct.
28+
29+
The tester will also verify that the record is persisted to the appropriate log file on disk at `<log-dir>/<topic-name>-<partition-index>/00000000000000000000.log` with sequential offsets.
30+
31+
## Notes
32+
33+
- Records within a batch must be assigned sequential offsets (e.g., if base offset is 5, records get offsets 5, 6, 7).
34+
- The entire batch is treated as a single atomic operation.
35+
- The response should return the base offset of the batch, not individual record offsets.
36+
- The official docs for the `Produce` request can be found [here](https://kafka.apache.org/protocol.html#The_Messages_Produce).
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
In this stage, you'll add support for producing to multiple partitions of the same topic in a single request.
2+
3+
## Partition Routing
4+
5+
Your Kafka implementation should handle writes to multiple partitions within the same topic, manage independent offset assignment per partition, and aggregate responses correctly. Each partition maintains its own offset sequence independently.
6+
7+
## Tests
8+
9+
The tester will execute your program like this:
10+
11+
```bash
12+
./your_program.sh /tmp/server.properties
13+
```
14+
15+
It'll then connect to your server on port 9092 and send a `Produce` (v11) request targeting multiple partitions of the same topic.
16+
17+
The tester will validate that:
18+
19+
- The first 4 bytes of your response (the "message length") are valid.
20+
- The correlation ID in the response header matches the correlation ID in the request header.
21+
- The error code in the response body is `0` (NO_ERROR).
22+
- The `throttle_time_ms` field in the response is `0`.
23+
- The `name` field in the topic response matches the topic name in the request.
24+
- Each partition in the request has a corresponding partition response.
25+
- Each partition response contains:
26+
- The correct `partition` field matching the request.
27+
- An error code of `0` (NO_ERROR).
28+
- A valid `offset` field with the assigned offset for that partition.
29+
- A valid `timestamp` field.
30+
- A correct `log_start_offset` field.
31+
- Records are persisted to the correct partition log files.
32+
- Offset assignment is independent per partition (partition 0 and partition 1 can both have offset 0).
33+
34+
## Notes
35+
36+
- Each partition maintains its own offset sequence starting from 0.
37+
- Multiple partitions can be written to simultaneously in a single request.
38+
- The response must include entries for all requested partitions.
39+
- Partition-level errors should be handled independently (one partition failure shouldn't affect others).
40+
- The official docs for the `Produce` request can be found [here](https://kafka.apache.org/protocol.html#The_Messages_Produce).
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
In this stage, you'll add support for producing to multiple topics in a single request.
2+
3+
## Cross-Topic Production
4+
5+
Your Kafka implementation should handle complex requests with multiple topics, manage independent offset tracking per topic and partition, and handle complex response structures. Each topic maintains completely independent offset sequences.
6+
7+
## Tests
8+
9+
The tester will execute your program like this:
10+
11+
```bash
12+
./your_program.sh /tmp/server.properties
13+
```
14+
15+
It'll then connect to your server on port 9092 and send a `Produce` (v11) request targeting multiple topics with their respective partitions.
16+
17+
The tester will validate that:
18+
19+
- The first 4 bytes of your response (the "message length") are valid.
20+
- The correlation ID in the response header matches the correlation ID in the request header.
21+
- The error code in the response body is `0` (NO_ERROR).
22+
- The `throttle_time_ms` field in the response is `0`.
23+
- Each topic in the request has a corresponding topic response.
24+
- Each topic response contains:
25+
- The correct `name` field matching the topic name in the request.
26+
- Each partition in the request has a corresponding partition response.
27+
- Each partition response contains:
28+
- The correct `partition` field matching the request.
29+
- An error code of `0` (NO_ERROR).
30+
- A valid `offset` field with the assigned offset for that topic-partition.
31+
- A valid `timestamp` field.
32+
- A correct `log_start_offset` field.
33+
- Records are persisted to the correct topic-partition log files.
34+
- Offset assignment is independent per topic-partition combination.
35+
36+
## Notes
37+
38+
- Each topic-partition combination maintains its own independent offset sequence.
39+
- Multiple topics can be written to simultaneously in a single request.
40+
- The response structure is nested: topics contain partition responses.
41+
- Topic-level and partition-level errors should be handled independently.
42+
- This is the most complex produce scenario, combining multi-topic and multi-partition handling.
43+
- The official docs for the `Produce` request can be found [here](https://kafka.apache.org/protocol.html#The_Messages_Produce).

0 commit comments

Comments
 (0)