Kafka broker wire: implementation reference

This page describes how the Kafka listener is built: framing, SASL, the API key table, how topics, partitions, offsets, consumer groups and transactions are stored, retention and compaction, errors, limits and tests. For the proof scores, how to connect and how to re-run the differential suites, see the operator page Kafka. Authentication policy across all wires is in Security. Schemas for Kafka payloads are served by a separate listener, described in Schema Registry.

1. Source layout

File Role
src/protocol/kafka/mod.rs KafkaHandler: listener, connection loop, SASL, the SUPPORTED version table, dispatch, every topic, produce, fetch, offset, group and transaction handler, the group and transaction coordinator state
src/protocol/kafka/log.rs KafkaLog: the storage-backed partition logs, key layout, per-partition index, idempotent producer state, retention and compaction
src/protocol/kafka/batch.rs Magic v2 record batch parsing, CRC-32C, decompression, control batch building
src/protocol/kafka/codec.rs Decoder / Encoder for classic and flexible (KIP-482) encodings
src/protocol/kafka/admin.rs DescribeCluster, DescribeLogDirs, the ACL APIs, DescribeProducers, DescribeTransactions, ListTransactions, ListPartitionReassignments, DescribeClientQuotas, ElectLeaders; the flexible version table
src/protocol/kafka/topic_config.rs Kafka 3.8 topic config defaults, override validation, topic name rules
src/protocol/kafka/broker_configs.rs, config_docs.rs Broker config list and documentation strings for DescribeConfigs
src/protocol/kafka/record.rs Record batch decoding shared with the SQL engine's kafka_consume table function

The module comment states the design: a single-node broker over the shared storage engine that speaks the classic request encodings at the versions of a Kafka 2.3 broker, plus flexible ApiVersions v3. Third-party crates used for record batches: flate2 (gzip), snap (snappy, raw and xerial framing), lz4_flex (lz4 frame) and zstd. CRC-32C is implemented in the module. (source: src/protocol/kafka/mod.rs, module comment; src/protocol/kafka/batch.rs, decompress, crc32c)

2. Listener and framing

  • Port: [server] kafka_port, default 9092. ProtocolHandler::default_port also returns 9092. (source: src/config.rs, ServerConfig::default; src/protocol/kafka/mod.rs, KafkaHandler::default_port)
  • Every accepted socket gets TCP_NODELAY and its own task. When TLS is configured, the socket goes through TlsListener::accept_auto, so TLS and plaintext clients share the port (first-byte detection). (source: src/protocol/kafka/mod.rs, KafkaHandler::start, KafkaHandler::with_tls)
  • A request is a 4-byte big-endian length, then the body. A length of 0 or less, or over 104,857,600 bytes (100 MiB, Kafka's socket.request.max.bytes default), closes the connection with no reply. (source: src/protocol/kafka/mod.rs, handle_connection)
  • The request header is read as api key, api version, correlation id and client id. For flexible versions (admin::flexible, and ApiVersions v3) the header tagged fields are skipped, and the response header carries one tagged-fields byte after the correlation id. ApiVersions keeps the v0 response header at every version, as Kafka does. (source: src/protocol/kafka/mod.rs, handle_connection; src/protocol/kafka/admin.rs, flexible)
  • An api key or version outside the SUPPORTED table closes the connection without a reply, which is what Kafka does. ApiVersions itself is always answered; a version above 3 is answered in the v0 format with UNSUPPORTED_VERSION and the full list, so the client retries lower. (source: src/protocol/kafka/mod.rs, handle_connection, version_supported, h_api_versions)
  • An acks=0 produce gets no reply (Reply::Silent). (source: src/protocol/kafka/mod.rs, Reply, h_produce)
  • JoinGroup, SyncGroup and Fetch can block and run on the async loop; every other API goes through the synchronous dispatch. Requests on one connection are answered in order. (source: src/protocol/kafka/mod.rs, handle_connection, dispatch)
  • A periodic tick every 500 ms expires group members, aborts timed-out and orphaned transactions, and schedules retention and compaction on a blocking thread (one maintenance run at a time). (source: src/protocol/kafka/mod.rs, KafkaHandler::start, sweep)

There is no idle or read timeout on this wire; a connection stays open until the client closes it or a framing error occurs. (source: src/protocol/kafka/mod.rs, handle_connection) Not verified: no test covers long-idle connections.

Advertised address

Metadata and FindCoordinator return one broker, node id 0, at an advertised host and port. The host comes from [server] kafka_advertised_host (host or host:port; read from SYNERGYDB_KAFKA_ADVERTISED_HOST at startup). When unset, the broker advertises the local address the connection arrived on; on a wildcard bind with no local address it falls back to 127.0.0.1. IPv4-mapped IPv6 addresses are advertised as IPv4. (source: src/config.rs, kafka_advertised_host; src/main.rs; src/protocol/kafka/mod.rs, parse_advertised, advertised_host) Tested by parse_advertised_forms, wildcard_bind_advertises_local_address_not_loopback and metadata_advertises_configured_host_and_port in src/protocol/kafka/mod.rs.

The cluster id is the fixed string synergydb and the controller id is 0. (source: src/protocol/kafka/mod.rs, CLUSTER_ID, NODE_ID)

3. Authentication

stateDiagram-v2 [*] --> Unauthenticated: require_sasl true [*] --> Authenticated: require_sasl false Unauthenticated --> Unauthenticated: ApiVersions (18), SaslHandshake (17) Unauthenticated --> Authenticated: SaslAuthenticate (36) ok Unauthenticated --> Closed: SaslAuthenticate failed (reply sent first) Unauthenticated --> Closed: any other API Authenticated --> Authenticated: any supported API

(source: src/protocol/kafka/mod.rs, handle_connection)

  • require_sasl comes from [server] kafka_require_sasl. When the key is unset, SASL is required unless SYNERGYDB_DEV_INSECURE_AUTH is 1 or true. (source: src/server/mod.rs, Kafka start block; src/protocol/kafka/mod.rs, KafkaHandler::with_storage; src/auth/wire_auth.rs, dev_insecure_auth_enabled)
  • SaslHandshake accepts PLAIN (case-insensitive) and lists only PLAIN as enabled; any other mechanism gets error 33 UNSUPPORTED_SASL_MECHANISM. There is no SCRAM, OAUTHBEARER or GSSAPI. (source: src/protocol/kafka/mod.rs, h_sasl_handshake)
  • SaslAuthenticate parses authzid NUL authcid NUL passwd and checks authcid and passwd with verify_wire_credential("kafka", ...): a catalog role and password, and the role must be a superuser or a member of synergy_wire_kafka or synergy_wire_all unless SYNERGYDB_WIRE_ACCESS is open, off or any. The authzid is ignored. A failure answers error 58 SASL_AUTHENTICATION_FAILED with "Authentication failed" and closes the connection. v1 adds session_lifetime_ms = 0 (no re-authentication). (source: src/protocol/kafka/mod.rs, h_sasl_authenticate, parse_sasl_plain; src/auth/wire_auth.rs, verify_wire_credential, wire_access_allowed)
  • Only SaslHandshake followed by SaslAuthenticate is supported. A client that sends raw SASL bytes without the Kafka framing (the pre-KIP-152 form) is closed, because the first frame is read as an unknown api key. (source: src/protocol/kafka/mod.rs, handle_connection)

Tested by sasl_required_broker_refuses_unauthenticated_requests and sasl_plain_with_a_catalog_role_unlocks_the_connection in tests/protocol_kafka.rs, and kafka_metadata_without_sasl_is_refused_by_default in tests/wire_preauth_gate.rs.

There is no authorizer. Once authenticated, a principal can produce, fetch, create and delete any topic and group. The ACL APIs answer SECURITY_DISABLED (54), and authorized-operation bitfields, when a client asks for them, report every operation as allowed. (source: src/protocol/kafka/admin.rs, module comment, describe_acls, create_acls, delete_acls; src/protocol/kafka/mod.rs, ops_mask, TOPIC_OPS, CLUSTER_OPS, GROUP_OPS)

Audit: when the audit log is on, Fetch (read), DeleteRecords (write), CreateTopics, DeleteTopics, CreateAcls, DeleteAcls, AlterConfigs, CreatePartitions, DeleteGroups, ElectLeaders, IncrementalAlterConfigs and OffsetDelete (admin) are recorded with wire kafka; for the topic APIs the first topic name is the object. Produce is recorded per partition with base offset, record count and error. (source: src/protocol/kafka/mod.rs, handle_connection, h_fetch, audit_kafka_produce) Not verified: no test of the Kafka audit records was found.

4. Supported APIs and versions

The SUPPORTED table is both what ApiVersions advertises and the gate on every request. It is the complete list; any other api key closes the connection. (source: src/protocol/kafka/mod.rs, SUPPORTED, dispatch, handle_connection)

Key API Versions Flexible from Handler
0 Produce 3-8 no h_produce
1 Fetch 4-11 no h_fetch, build_fetch
2 ListOffsets 1-5 no h_list_offsets
3 Metadata 0-8 no h_metadata
8 OffsetCommit 2-7 no h_offset_commit
9 OffsetFetch 1-5 no h_offset_fetch
10 FindCoordinator 0-2 no h_find_coordinator
11 JoinGroup 0-5 no h_join_group
12 Heartbeat 0-3 no h_heartbeat
13 LeaveGroup 0-2 no h_leave_group
14 SyncGroup 0-3 no h_sync_group
15 DescribeGroups 0-4 no h_describe_groups
16 ListGroups 0-2 no h_list_groups
17 SaslHandshake 0-1 no h_sasl_handshake
18 ApiVersions 0-3 v3 h_api_versions
19 CreateTopics 0-4 no h_create_topics
20 DeleteTopics 0-3 no h_delete_topics
21 DeleteRecords 0-1 no h_delete_records
22 InitProducerId 0-1 no h_init_producer_id
24 AddPartitionsToTxn 0-1 no h_add_partitions_to_txn
25 AddOffsetsToTxn 0-1 no h_add_offsets_to_txn
26 EndTxn 0-1 no h_end_txn
28 TxnOffsetCommit 0-2 no h_txn_offset_commit
29 DescribeAcls 0-3 v2 admin::describe_acls (SECURITY_DISABLED)
30 CreateAcls 0-3 v2 admin::create_acls (SECURITY_DISABLED)
31 DeleteAcls 0-3 v2 admin::delete_acls (SECURITY_DISABLED)
32 DescribeConfigs 0-4 v4 h_describe_configs
33 AlterConfigs 0-1 no h_alter_configs
35 DescribeLogDirs 0-4 v2 admin::describe_log_dirs
36 SaslAuthenticate 0-1 no h_sasl_authenticate
37 CreatePartitions 0-1 no h_create_partitions
42 DeleteGroups 0-1 no h_delete_groups
43 ElectLeaders 0-2 v2 admin::elect_leaders
44 IncrementalAlterConfigs 0 no h_alter_configs (incremental)
46 ListPartitionReassignments 0 v0 admin::list_partition_reassignments (always empty)
47 OffsetDelete 0 no h_offset_delete
48 DescribeClientQuotas 0-1 v1 admin::describe_client_quotas (always empty)
60 DescribeCluster 0-1 v0 admin::describe_cluster
61 DescribeProducers 0 v0 admin::describe_producers
65 DescribeTransactions 0 v0 admin::describe_transactions
66 ListTransactions 0-1 v0 admin::list_transactions

(source: src/protocol/kafka/mod.rs, SUPPORTED, dispatch; src/protocol/kafka/admin.rs, flexible)

ApiVersions v3 also carries the supported and finalized metadata.version feature at level 20 (3.8-IV0), with finalized-features epoch 1, so kafka-features describe reads a Kafka 3.8 cluster. (source: src/protocol/kafka/mod.rs, h_api_versions, METADATA_VERSION)

The version floors keep clients on magic v2 record batches: Produce starts at v3 and Fetch at v4. A batch with an older magic byte is refused with UNSUPPORTED_FOR_MESSAGE_FORMAT (43). (source: src/protocol/kafka/mod.rs, SUPPORTED comment; src/protocol/kafka/batch.rs, split_batches) Tested by old_magic_rejected in src/protocol/kafka/batch.rs.

Not implemented

Any api key not in the table, including LeaderAndIsr, StopReplica, UpdateMetadata and ControlledShutdown (4 to 7), OffsetForLeaderEpoch (23), WriteTxnMarkers (27), AlterReplicaLogDirs (34), the SASL re-authentication and delegation token APIs (38 to 41), AlterPartitionReassignments (45), AlterClientQuotas (49), the SCRAM credential APIs (50, 51), the KRaft and controller APIs, UpdateFeatures (57), DescribeTopicPartitions (75, KIP-966) and ConsumerGroupHeartbeat (68, the KIP-848 group protocol). Clients that probe DescribeTopicPartitions fall back to Metadata. Fetch sessions (KIP-227) are not kept: every Fetch response carries session id 0, so clients send full fetches. (source: src/protocol/kafka/mod.rs, SUPPORTED, h_fetch, build_fetch)

5. Topics and partitions

  • CreateTopics. Validates names (non-empty, not . or .., at most 249 characters, only ASCII letters, digits, ., _ and -), refuses duplicates in one request (INVALID_REQUEST), existing topics (TOPIC_ALREADY_EXISTS), zero or negative partitions other than -1 (INVALID_PARTITIONS), replication factor 0, below -1 or above 1 (INVALID_REPLICATION_FACTOR, with Kafka's "only 1 broker(s) are registered" text), and replica assignments that name a broker other than 0 or more than one broker (INVALID_REPLICA_ASSIGNMENT). -1 partitions means 1 (num.partitions). Config overrides are validated (INVALID_CONFIG) and stored; validate_only (v1 and later) checks without creating. (source: src/protocol/kafka/mod.rs, h_create_topics; src/protocol/kafka/topic_config.rs, validate_topic_name, validate)
  • Metadata auto-creation. A Metadata request naming an unknown valid topic creates it with one partition when allow_auto_topic_creation is true (always true below v4). A Metadata request with a null list (or an empty list at v0) lists every topic. Each partition reports leader 0, leader epoch 0, replicas [0] and ISR [0]; is_internal is always false. (source: src/protocol/kafka/mod.rs, h_metadata) There is no broker setting to turn auto-creation off.
  • CreatePartitions only grows a topic; a lower count or the same count is refused with Kafka's messages. DeleteTopics removes the topic, its config, its record batches, aborted-transaction ranges, next-offset, log-start and cleaner records, and every group's committed offsets for it, in write batches of 4,096 keys. (source: src/protocol/kafka/mod.rs, h_create_partitions, h_delete_topics; src/protocol/kafka/log.rs, KafkaLog::delete_topic)
  • DeleteRecords moves the log start offset forward and deletes whole batches whose last offset is below it. On a compacted topic it is refused with POLICY_VIOLATION. (source: src/protocol/kafka/log.rs, KafkaLog::delete_records_before; docs/status/2026-11-24-kafka-admin-apis-retention.md)
  • DescribeConfigs / AlterConfigs / IncrementalAlterConfigs read and write topic overrides, and report the Kafka 3.8 broker config list with sources, synonyms and documentation (v3 and later). log.retention.check.interval.ms and log.cleaner.backoff.ms report the intervals actually in use. (source: src/protocol/kafka/mod.rs, h_describe_configs, h_alter_configs; src/protocol/kafka/broker_configs.rs; docs/status/2026-11-27-kafka-broker-config-intervals.md)

Tested by create_topic_then_metadata_reports_its_partitions, partitions_are_independent_logs, delete_topic_removes_it, and names and configs in src/protocol/kafka/topic_config.rs.

6. Produce

For each partition in the request, h_produce checks, in order: acks is -1, 0 or 1 (INVALID_REQUIRED_ACKS); the topic exists (UNKNOWN_TOPIC_OR_PARTITION; Produce does not auto-create); the partition is in range; the record set splits into valid batches; no batch exceeds the topic's max.message.bytes (default 1,048,588; MESSAGE_TOO_LARGE with Kafka's message); on a compacted topic every record has a key (INVALID_RECORD); and transactional batches belong to a producer that added the partition to its open transaction. Then KafkaLog::append_batches stores them. (source: src/protocol/kafka/mod.rs, h_produce, txn_batch_error; src/protocol/kafka/topic_config.rs, max_message_bytes)

batch::split_batches checks each batch's length, magic byte 2 and CRC-32C over bytes 21 to the end. A bad CRC or truncated batch is CORRUPT_MESSAGE (2). A control batch from a client is INVALID_RECORD (87). Compressed batches (gzip, snappy, lz4, zstd) are stored compressed, as written; they are decompressed only to check keys on compacted topics, for compaction and for kafka_consume. (source: src/protocol/kafka/batch.rs, split_batches, decompress) Tested by crc32c_known_vector, corrupt_crc_rejected and control_batch_validates_and_decodes in batch.rs, and corrupt_batches_and_unknown_topics_are_rejected in tests/protocol_kafka.rs.

append_batches assigns offsets: it stamps the broker's base offset into bytes 0 to 7 and leader epoch 0 into bytes 12 to 15, which the CRC does not cover, and writes every batch plus the new next-offset record in one StorageEngine::write_batch before the reply. acks=1 and acks=all take the same path. A storage failure answers KAFKA_STORAGE_ERROR (56). (source: src/protocol/kafka/log.rs, KafkaLog::append_batches) Tested by produce_fetch_round_trip_assigns_consecutive_offsets and records_survive_a_broker_restart.

Idempotent producers. Per producer id and partition, the log keeps the epoch and the last five (first sequence, last sequence, base offset) ranges. An older epoch is INVALID_PRODUCER_EPOCH (47). A retry of a stored range is answered with its original base offset and not written again. A sequence that is not the next one, or a new epoch not starting at 0, is OUT_OF_ORDER_SEQUENCE (45). This state is rebuilt from the batch headers when a partition is loaded, so it survives a restart. (source: src/protocol/kafka/log.rs, ProducerEntry, append_batches, load_part; docs/status/2026-11-24-kafka-idempotent-restart.md) Tested by idempotent_retry_returns_the_original_offset and idempotent_retry_after_restart_is_not_duplicated.

Producer ids come from a persisted counter (kfk\x09pid) and start at 1. (source: src/protocol/kafka/log.rs, next_producer_id, K_PID)

7. Fetch and ListOffsets

  • Fetch reads max_wait (capped at 30 s), min_bytes, the response max_bytes (v3 and later), the isolation level (v4 and later) and, per partition, the fetch offset and partition max_bytes. It builds a response; if the record bytes are below min_bytes, no partition errored and the deadline has not passed, it waits for the log's append notification and builds again (long polling). (source: src/protocol/kafka/mod.rs, h_fetch, MAX_FETCH_WAIT_MS)
  • A fetch offset below the log start or above the high watermark is OFFSET_OUT_OF_RANGE. Reading starts at the batch that contains the fetch offset, so a client can fetch from inside a batch and skip the leading records itself, as on Kafka. The first partition with data always returns at least one whole batch even when it is larger than max_bytes. (source: src/protocol/kafka/mod.rs, build_fetch; src/protocol/kafka/log.rs, KafkaLog::read) Tested by fetch_inside_a_batch_and_past_the_end.
  • read_committed (isolation 1) reads only up to the last stable offset (the first offset of the oldest open transaction) and returns the aborted-transaction list for the range; read_uncommitted reads to the high watermark. (source: src/protocol/kafka/mod.rs, build_fetch; src/protocol/kafka/log.rs, PartState::lso, aborted_in)
  • preferred_read_replica is -1 and responses never throttle. (source: src/protocol/kafka/mod.rs, build_fetch)
  • ListOffsets: timestamp -2 is the log start, -1 the high watermark (or LSO under read_committed), and a non-negative timestamp the first offset whose batch has a record at or after it, from the per-partition index. Other negative values are INVALID_REQUEST. (source: src/protocol/kafka/mod.rs, h_list_offsets; src/protocol/kafka/log.rs, offset_for_time)

8. Consumer groups

Group membership is held in memory in a map of GroupState keyed by group id; only the protocol type of each group and its committed offsets are stored. A restart makes members re-join, as on Kafka. (source: src/protocol/kafka/mod.rs, module comment, Phase, Groups)

stateDiagram-v2 [*] --> Empty Empty --> Joining: JoinGroup Joining --> Syncing: all members re-joined, or rebalance timeout Syncing --> Stable: leader's SyncGroup assignment Stable --> Joining: member joins, leaves or expires Joining --> Empty: last member leaves Stable --> Empty: last member leaves

(source: src/protocol/kafka/mod.rs, Phase, start_rebalance, try_complete_join, remove_member; DescribeGroups reports the phases as Empty, PreparingRebalance, CompletingRebalance, Stable)

  • JoinGroup refuses an empty group id (INVALID_GROUP_ID), a session timeout outside 6,000 to 1,800,000 ms (INVALID_SESSION_TIMEOUT), and a protocol type or protocol list that does not match the group (INCONSISTENT_GROUP_PROTOCOL). From v4 a member with no id is handed one (<client id>-<uuid>) with MEMBER_ID_REQUIRED and re-joins with it (KIP-394). The joiner parks until the round closes: every current member has re-joined, or the longest rebalance timeout runs out (capped at 30 s). The first member to join leads and alone receives the member list. The group protocol is chosen among the protocols every member supports: each member votes for the first of those in its own list, and the most votes wins (ties go to the earliest candidate). (source: src/protocol/kafka/mod.rs, h_join_group, select_protocol, MIN_SESSION_TIMEOUT_MS, MAX_SESSION_TIMEOUT_MS, MAX_REBALANCE_WAIT)
  • Initial rebalance delay. A brand-new group closes its first round after 100 ms, so consumers started together share one generation. SYNERGYDB_KAFKA_INITIAL_REBALANCE_DELAY_MS overrides it (Kafka's default group.initial.rebalance.delay.ms is 3 s). (source: src/protocol/kafka/mod.rs, initial_rebalance_delay)
  • SyncGroup: followers wait up to 30 s for the leader's assignment. Heartbeat refreshes the member's session; it answers REBALANCE_IN_PROGRESS while a join round is open, ILLEGAL_GENERATION for a stale generation and UNKNOWN_MEMBER_ID for an unknown group or member. LeaveGroup removes the member and starts a rebalance. Members whose session timeout passes without a heartbeat are removed by the 500 ms sweep. (source: src/protocol/kafka/mod.rs, h_sync_group, h_heartbeat, h_leave_group, sweep, SYNC_DEADLINE)
  • OffsetCommit (commit_check): a commit for an unknown group is allowed only with generation -1. A standalone commit (generation -1, empty member id) is allowed only while the group has no members. Otherwise the member must exist (UNKNOWN_MEMBER_ID) and the generation must match (ILLEGAL_GENERATION). A commit is refused with REBALANCE_IN_PROGRESS only between the join round closing and the assignment arriving; a code comment explains that refusing commits during the join round made Kafka Streams re-process input. Metadata longer than 4,096 bytes is OFFSET_METADATA_TOO_LARGE. Commit retention time (v2 to v4) is read and ignored: committed offsets never expire. (source: src/protocol/kafka/mod.rs, commit_check, h_offset_commit)
  • OffsetFetch returns -1 and empty metadata for partitions with no commit. DescribeGroups, ListGroups, DeleteGroups (NON_EMPTY_GROUP for an active group, GROUP_ID_NOT_FOUND for an unknown one) and OffsetDelete (GROUP_SUBSCRIBED_TO_TOPIC while a member is subscribed) cover groups known in memory or by a stored protocol type. (source: src/protocol/kafka/mod.rs, h_offset_fetch, h_describe_groups, h_list_groups, h_delete_groups, h_offset_delete)
  • FindCoordinator accepts key type 0 (group) and 1 (transaction) and always names broker 0. (source: src/protocol/kafka/mod.rs, h_find_coordinator)

Not verified: no Rust test covers JoinGroup, SyncGroup, Heartbeat, rebalancing or offset commits. They are covered by the Python differential suite behind kafka-kafka-diff.txt (section 13).

9. Transactions

  • InitProducerId with no transactional id allocates a new producer id with epoch 0. With a transactional id, the timeout must be between 1 and 900,000 ms (INVALID_TRANSACTION_TIMEOUT); a repeat call bumps the epoch, fencing the previous instance, and aborts the transaction it left open. (source: src/protocol/kafka/mod.rs, h_init_producer_id, MAX_TXN_TIMEOUT_MS)
  • AddPartitionsToTxn, AddOffsetsToTxn, TxnOffsetCommit and EndTxn check producer id and epoch (INVALID_PRODUCER_ID_MAPPING, INVALID_PRODUCER_EPOCH, INVALID_TXN_STATE). EndTxn writes a COMMIT or ABORT control batch to each partition in the transaction; an abort also stores the aborted range (kfk\x06) for read_committed fetches. TxnOffsetCommit needs the group to have been added with AddOffsetsToTxn (INVALID_TXN_STATE otherwise); its offsets are held with the transaction and stored only when EndTxn commits. (source: src/protocol/kafka/mod.rs, h_add_partitions_to_txn, h_add_offsets_to_txn, h_txn_offset_commit, h_end_txn, finish_txn; src/protocol/kafka/log.rs, write_txn_marker; src/protocol/kafka/batch.rs, control_batch)
  • A transaction that outlives its timeout is aborted by the sweep and the producer's epoch is bumped. (source: src/protocol/kafka/mod.rs, sweep)
  • Coordinator state is in memory only. After a restart, each partition rebuilds its open transactions from the log (transactional batches with no marker after them). Any open transaction that no coordinator state owns is aborted after 60 s (SYNERGYDB_KAFKA_ORPHAN_TXN_TIMEOUT_MS) by writing an abort marker, so the last stable offset moves on. (source: src/protocol/kafka/log.rs, load_part, abort_orphan_txns; src/protocol/kafka/mod.rs, orphan_txn_timeout) Tested by open_txn_survives_restart_and_orphan_is_aborted in src/protocol/kafka/log.rs.

The status entry for that fix records a remaining gap: after a restart, a producer's EndTxn for a transaction begun before the crash is answered as if it succeeded, and the transaction is then aborted as an orphan, where Kafka would return a fencing error. (source: docs/status/2026-11-30-kafka-orphan-txn.md)

10. Storage layout

Everything is in the shared storage engine's key space under the prefix kfk and a type byte. Strings marked L are a u16 big-endian length then the bytes; integers are big-endian. (source: src/protocol/kafka/log.rs, module comment, P_* constants)

Key Value
kfk\x01 L topic, partition i32, base offset u64 One record batch: the producer's v2 batch bytes with the broker's base offset stamped in
kfk\x02 L topic, partition i32 Next offset (high watermark) u64
kfk\x03 topic Partition count u32
kfk\x04 L group, L topic, partition i32 Committed offset i64 followed by the metadata string
kfk\x05 group Group protocol type
kfk\x06 L topic, partition, first offset u64, producer id i64 Last offset u64 of an aborted transaction
kfk\x07 topic Encoded topic config overrides
kfk\x08 L topic, partition i32 Log start offset u64
kfk\x09pid Producer id counter i64
kfk\x0a L topic, partition i32 Cleaner state: frozen offset, cleaned-up-to offset, last clean time, segment bases

Because the batch key ends in the base offset, a prefix scan returns batches in offset order, which is the fetch order. Per partition, an in-memory index (base offset to last offset, max timestamp, control flag), the stored size of each batch, aborted ranges, open transactions and producer state are built lazily from the stored batches the first time the partition is used. (source: src/protocol/kafka/log.rs, PartState, load_part, with_part)

Records, topics, configs, committed offsets, aborted ranges, log start offsets, cleaner state and the producer id counter are durable. Group membership and transaction coordinator state are not. (source: src/protocol/kafka/mod.rs, module comment)

SQL access. SELECT * FROM kafka_consume('<topic>') (also kafka(...)) on a SQL wire scans the stored batches of partition 0 and returns offset, timestamp, key, value (key and value as lossy UTF-8 text). Control batches yield no rows. (source: src/query/engine.rs, the KAFKA_CONSUME arm; src/protocol/kafka/record.rs, record_scan_range, decode_record_batch) Not verified: no test of kafka_consume was found. From the code, it reads only partition 0, returns the records of aborted transactions as well as committed ones, and does not apply the synergy_wire_kafka check (access is decided by the SQL session). The unit tests in record.rs cover only malformed headers (malformed_header_varint_terminates, huge_header_count_terminates).

11. Retention and compaction

The broker tick schedules KafkaLog::maintain on a blocking thread:

  • Retention runs every SYNERGYDB_KAFKA_RETENTION_CHECK_INTERVAL_MS (default 300,000, Kafka's log.retention.check.interval.ms). It applies retention.ms and retention.bytes to segments rolled on segment.bytes and segment.ms against the batches' own timestamps, and deletes only whole segments. (source: src/protocol/kafka/admin.rs, retention_check_interval_ms; src/protocol/kafka/log.rs, enforce_retention, PartState::segments, policy)
  • The cleaner runs every SYNERGYDB_KAFKA_CLEANER_BACKOFF_MS (default 15,000, Kafka's log.cleaner.backoff.ms) for cleanup.policy=compact or compact,delete, honouring min.cleanable.dirty.ratio, min.compaction.lag.ms and delete.retention.ms for tombstones. The newest segment is never cleaned, segment boundaries are kept after cleaning, and cleaner state is stored. (source: src/protocol/kafka/admin.rs, cleaner_backoff_ms; src/protocol/kafka/log.rs, compact, LogPolicy)
  • The cleaner leaves transactional batches as they are. (source: README.md, Known gaps; docs/proof/2026-11-30/proof-pack-a3232c9/report.md, Kafka known gaps)

Covered by the retention differential suite (kafka-kafka-retention-diff.txt, 14/14). Not verified: no Rust test covers retention or compaction.

12. Errors, limits and configuration

Kafka error codes the wire returns, from the constants in the module:

Code Name Typical cause
1 OFFSET_OUT_OF_RANGE Fetch below log start or above the high watermark
2 CORRUPT_MESSAGE Bad CRC, length or truncated batch
3 UNKNOWN_TOPIC_OR_PARTITION Topic missing, partition out of range
10 MESSAGE_TOO_LARGE Batch over max.message.bytes
12 OFFSET_METADATA_TOO_LARGE Commit metadata over 4,096 bytes
17 INVALID_TOPIC_EXCEPTION Bad topic name
21 INVALID_REQUIRED_ACKS acks not -1, 0 or 1
22, 25, 27 ILLEGAL_GENERATION, UNKNOWN_MEMBER_ID, REBALANCE_IN_PROGRESS Group membership checks
23, 24, 26, 79 INCONSISTENT_GROUP_PROTOCOL, INVALID_GROUP_ID, INVALID_SESSION_TIMEOUT, MEMBER_ID_REQUIRED JoinGroup
33, 58 UNSUPPORTED_SASL_MECHANISM, SASL_AUTHENTICATION_FAILED SASL
35 UNSUPPORTED_VERSION ApiVersions above v3
36, 37, 38, 39, 40, 42 TOPIC_ALREADY_EXISTS, INVALID_PARTITIONS, INVALID_REPLICATION_FACTOR, INVALID_REPLICA_ASSIGNMENT, INVALID_CONFIG, INVALID_REQUEST Topic admin
43 UNSUPPORTED_FOR_MESSAGE_FORMAT Magic byte other than 2
44 POLICY_VIOLATION DeleteRecords on a compacted topic
45, 47 OUT_OF_ORDER_SEQUENCE, INVALID_PRODUCER_EPOCH Idempotent producer checks
48, 49, 50 INVALID_TXN_STATE, INVALID_PRODUCER_ID_MAPPING, INVALID_TRANSACTION_TIMEOUT Transactions
54 SECURITY_DISABLED ACL APIs
56 KAFKA_STORAGE_ERROR Storage write failed
68, 69, 86 NON_EMPTY_GROUP, GROUP_ID_NOT_FOUND, GROUP_SUBSCRIBED_TO_TOPIC DeleteGroups, OffsetDelete
84, 105, 115 ELECTION_NOT_NEEDED, TRANSACTIONAL_ID_NOT_FOUND, UNSUPPORTED_ENDPOINT_TYPE ElectLeaders, DescribeTransactions, DescribeCluster
87 INVALID_RECORD Keyless record on a compacted topic, client control batch

(source: src/protocol/kafka/mod.rs, error code constants; src/protocol/kafka/batch.rs, ERR_*; src/protocol/kafka/log.rs, ERR_*; src/protocol/kafka/admin.rs, constants)

Setting Default Effect
[server] kafka_port 9092 Listener port; removing it disables the wire
[server] kafka_require_sasl unset (SASL required) false lets every client in without SASL
[server] kafka_advertised_host / SYNERGYDB_KAFKA_ADVERTISED_HOST unset Host or host:port returned in Metadata and FindCoordinator
SYNERGYDB_DEV_INSECURE_AUTH unset When kafka_require_sasl is unset, 1/true turns SASL off
SYNERGYDB_WIRE_ACCESS enforced open/off/any drops the synergy_wire_kafka membership check
SYNERGYDB_KAFKA_INITIAL_REBALANCE_DELAY_MS 100 First-generation delay for a new group
SYNERGYDB_KAFKA_ORPHAN_TXN_TIMEOUT_MS 60,000 Abort delay for open transactions with no coordinator state
SYNERGYDB_KAFKA_RETENTION_CHECK_INTERVAL_MS 300,000 Retention interval
SYNERGYDB_KAFKA_CLEANER_BACKOFF_MS 15,000 Cleaner interval
Request size (constant) 104,857,600 bytes Larger frames close the connection
Fetch wait (constant) 30 s Cap on max_wait
Session timeout (constants) 6,000 to 1,800,000 ms JoinGroup range
Transaction timeout (constant) 900,000 ms InitProducerId maximum

(source: src/config.rs, ServerConfig; src/server/mod.rs; src/protocol/kafka/mod.rs, constants and env readers; src/protocol/kafka/admin.rs, retention_check_interval_ms, cleaner_backoff_ms)

TLS uses the server-wide TLS settings; there is no Kafka-specific TLS key. Without TLS, SASL/PLAIN passwords cross the network in clear text. (source: src/protocol/kafka/mod.rs, with_tls; Security)

13. Tests and proof evidence

Where What
tests/protocol_kafka.rs (13 tests) A real KafkaHandler over TCP with hand-written encoders, independent of the server's codec: ApiVersions, CreateTopics plus Metadata, produce and fetch offsets, independent partitions, out-of-range partition, restart durability, SASL refusal and SASL login with a catalog role, idempotent retry before and after restart, fetch inside a batch and past the end, corrupt batches and unknown topics, DeleteTopics
tests/wire_preauth_gate.rs kafka_metadata_without_sasl_is_refused_by_default: the default handler closes an unauthenticated Metadata request without a reply
Unit tests mod.rs 3 (advertised address), batch.rs 4 (CRC, control batch, bad CRC, old magic), log.rs 1 (orphan transaction after restart), record.rs 2, topic_config.rs 2
docs/proof/2026-11-30/proof-pack-a3232c9/logs/kafka-kafka-diff.txt Differential against Apache Kafka 3.8 with kafka-python, librdkafka and Kafka's CLI tools: 111/111 (single connection 98/98, second connection 5/5, after restart 8/8)
.../logs/kafka-kafka-retention-diff.txt Retention and compaction against a Kafka 3.8 broker checking every second: 14/14 (single 13/13, after restart 1/1)

Together these are the 125/125 on the operator page (same connection 111, second connection 5, restart 9). (source: docs/proof/2026-11-30/proof-pack-a3232c9/report.md, Kafka section; Kafka)

The Rust tests encode only classic, non-flexible request versions and do not cover consumer groups, transactions, the admin APIs, compression codecs, read_committed, retention or TLS. Those are covered only by the Python suites behind the proof logs (test-scripts/diff-kafka/, test-scripts/diff-kafka-retention/), which are not in the reviewed snapshot.