[{"id":"kafkaadvanced-001","courseId":"kafka-advanced","domain":"log-and-storage","topic":"Record batch length rule","prompt":"A reader parses a record batch on disk and reads its batchLength field as 500. Counting every byte of the batch from its first byte, how large is the batch on disk?","hint":"Work out which header fields the length counts, and which sit outside it.","explain":"The length field does not count itself or the bytes before it. To find a batch's full size, you have to account for the header fields that sit outside the count.","source":"https://kafka.apache.org/43/implementation/message-format/#record-batch","interaction":{"type":"single"},"options":[{"id":"a","text":"500 bytes","whyNot":"batchLength starts after its own field, so 500 leaves out the 8-byte baseOffset and the 4-byte length field."},{"id":"b","text":"508 bytes","whyNot":"That adds only the 8-byte baseOffset; the 4-byte batchLength field is outside the count too."},{"id":"c","text":"512 bytes","why":"The batch is batchLength + 12 bytes: the 8-byte baseOffset plus the 4-byte batchLength field itself."},{"id":"d","text":"516 bytes","whyNot":"That adds 16, but the magic byte and CRC come after batchLength, so they are already inside the count."}],"answer":"c","explanation":"A record batch's batchLength counts the bytes after the length field, so the full on-disk size is batchLength plus the 12 bytes of baseOffset and the length field.","concept":"A record batch's batchLength counts the bytes after the length field, so the full on-disk size is batchLength plus the 12 bytes of baseOffset and the length field.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["batchLength excludes baseOffset and itself; add 12 bytes to get a batch's on-disk size."]},{"id":"kafkaadvanced-002","courseId":"kafka-advanced","domain":"log-and-storage","topic":"Record batch magic value","prompt":"A client reading a record batch can interpret the crc field before it checks the magic byte, because the crc sits ahead of magic in the layout.","hint":"Check where the CRC sits relative to the version byte, and what a client must read first.","explain":"Every batch carries a version byte that tells readers how to interpret the bytes around it. Its position relative to the checksum decides what a reader can safely decode first.","source":"https://kafka.apache.org/43/implementation/message-format/#record-batch","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The CRC is located after the magic byte, so a client must parse magic before it can decide how to read the bytes ahead of it."},{"id":"b","text":"False","why":"Magic comes before the CRC. Clients parse it first, because it determines how the bytes between batchLength and magic are read."}],"answer":"b","explanation":"The magic byte is the record batch format version, currently 2. It sits before the CRC, so clients parse it before reading the bytes that depend on the version.","concept":"The magic byte is the record batch format version, currently 2. It sits before the CRC, so clients parse it before reading the bytes that depend on the version.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["The magic byte comes before the CRC, so version-dependent parsing happens before the checksum is read."]},{"id":"kafkaadvanced-003","courseId":"kafka-advanced","domain":"log-and-storage","topic":"Batch attributes and compression","prompt":"A record batch's attributes field has bit 4 set. What does that bit tell a reader about the batch?","hint":"Each attribute bit carries one flag; look up what bit 4 alone means.","explain":"The attributes field packs several flags into single bits. The low bits hold the compression codec, and the higher bits are on/off properties, so one bit answers one question.","source":"https://kafka.apache.org/43/implementation/message-format/#record-batch","interaction":{"type":"single"},"options":[{"id":"a","text":"The batch belongs to a transaction.","why":"Bit 4 is isTransactional, so a set bit means the batch is transactional."},{"id":"b","text":"The batch is a commit or abort marker.","whyNot":"That describes bit 5, isControlBatch; bit 4 only marks transactional batches."},{"id":"c","text":"The records are gzip-compressed.","whyNot":"Compression is a codec number in bits 0 to 2; gzip is codec 1, and bit 4 says nothing about it."},{"id":"d","text":"The batch has a delete horizon timestamp.","whyNot":"That is bit 6, hasDeleteHorizonMs, which is a separate flag."}],"answer":"a","explanation":"Batch attributes pack flags into bits: bits 0 to 2 hold the codec, bit 4 marks transactional batches, bit 5 marks control batches, and bit 6 marks a delete horizon.","concept":"Batch attributes pack flags into bits: bits 0 to 2 hold the codec, bit 4 marks transactional batches, bit 5 marks control batches, and bit 6 marks a delete horizon.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Each attribute bit carries one flag, so check the bit number before reading a batch's type."]},{"id":"kafkaadvanced-004","courseId":"kafka-advanced","domain":"log-and-storage","topic":"Control batch markers","prompt":"A transactional producer writes commit and abort markers into a partition's log. Which TWO statements about these control batches and their control records are correct?","hint":"Think about who reads control records, and which part of the key is readable.","explain":"A log can hold special batches written by the transaction machinery rather than by the application. Think about who should see these records, and what a reader is expected to do with them.","source":"https://kafka.apache.org/43/implementation/message-format/#control-batches","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The key's type field is 0 for abort and 1 for commit.","why":"The key schema has a type int16 where 0 indicates an abort marker and 1 indicates a commit."},{"id":"b","text":"Consumers use these markers to filter out aborted transactional messages.","why":"The passage says consumers use control records to filter out aborted transactional messages."},{"id":"c","text":"Applications receive control records so they can track commits.","whyNot":"Control records should not be passed on to applications."},{"id":"d","text":"Clients parse the value to read the commit timestamp.","whyNot":"The value's schema is opaque to clients, so they do not parse it."},{"id":"e","text":"A control batch holds one control record per message in the transaction.","whyNot":"A control batch contains a single record, the control record."},{"id":"f","text":"Type 1 marks an abort and type 0 marks a commit.","whyNot":"It is the other way round: 0 is the abort marker and 1 is the commit."}],"answer":"ab","explanation":"A control batch holds one control record; its key gives a version and a type (0 abort, 1 commit). Consumers use these markers to filter aborted transactions, and the value is opaque to clients.","concept":"A control batch holds one control record; its key gives a version and a type (0 abort, 1 commit). Consumers use these markers to filter aborted transactions, and the value is opaque to clients.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Control records are log markers for consumers, not application data; their key sets abort or commit."]},{"id":"kafkaadvanced-005","courseId":"kafka-advanced","domain":"log-and-storage","topic":"Active segment exemption from compaction","prompt":"A compacted topic sets log.cleaner.min.compaction.lag.ms to one hour. Its only segment is still receiving writes, and every message in it is older than an hour. Can the log cleaner compact that segment?","hint":"Age is one test; check which segments the cleaner skips regardless of age.","explain":"Cleaning rewrites log segment files, and the lag setting holds back only messages newer than a minimum age. Before the age check matters, ask which segments are eligible at all.","source":"https://kafka.apache.org/43/design/design/#configuring-the-log-cleaner","interaction":{"type":"single"},"options":[{"id":"a","text":"Yes: every message is older than the minimum lag, so the segment qualifies.","whyNot":"Age is only one test. The segment is still being written to, and the active segment is excluded from compaction."},{"id":"b","text":"No: the active segment is never compacted, even when its messages all pass the lag.","why":"The last segment, the one currently being written to, is exempt, so the age of its messages does not make it eligible."},{"id":"c","text":"Yes, once the lag passes, because the cleaner ignores which segment is being written.","whyNot":"The cleaner does respect the active segment: the exemption applies even when all messages are older than the lag."},{"id":"d","text":"Yes, but only after the broker restarts, which resets the active segment.","whyNot":"Restarts do not make the active segment eligible; it is skipped while it is still being written to."}],"answer":"b","explanation":"Log cleaning is controlled by lag settings, but the segment currently being written to is always excluded. Segments qualify only after they are no longer active.","concept":"Log cleaning is controlled by lag settings, but the segment currently being written to is always excluded. Segments qualify only after they are no longer active.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Age alone does not make a segment compactable; the one being written to is always skipped."]}]