Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

Kafka Wire Protocol Specification

This documentation provides a comprehensive specification of the Apache Kafka binary wire protocol. The protocol defines how clients communicate with brokers over TCP connections using a request-response model with explicit versioning.


This specification covers Kafka protocol versions for Kafka 2.8 through 4.1. For the authoritative grammar reference and exhaustive API schemas, the Apache Kafka Protocol Documentation provides additional detail. This documentation provides:

  • Behavioral contracts and guarantees
  • Failure semantics and error handling
  • Implementation guidance and constraints
  • Version-specific behavioral differences
  • Complete error code reference with recovery actions

DocumentDescription
Protocol PrimitivesData types: integers, varints, strings, bytes, arrays, tagged fields
Protocol MessagesMessage framing, request/response headers, correlation IDs
Protocol RecordsRecord batch format, compression, timestamps, transactions
Protocol ErrorsComplete error code reference (count varies by version)
DocumentAPIs Covered
Core APIsProduce, Fetch, Metadata, ListOffsets, ApiVersions
Consumer APIsFindCoordinator, JoinGroup, Heartbeat, SyncGroup, OffsetCommit
Admin APIsCreateTopics, DeleteTopics, ACLs, Configs, ElectLeaders
Transaction APIsInitProducerId, AddPartitionsToTxn, EndTxn, TxnOffsetCommit

The Kafka protocol is a binary, request-response protocol with the following characteristics:

PrincipleDescription
Binary encodingAll messages use binary encoding for efficiency
Length-prefixedMessages are prefixed with a 4-byte size field
Explicit versioningEach API request specifies its version
Correlation-basedRequests and responses matched by correlation ID
MultiplexedMultiple requests may be in-flight per connection
ClientBrokerClientClientBrokerBrokerConnection SetupTCP ConnectApiVersionsRequestApiVersionsResponse (supported versions)Optional AuthenticationSaslHandshakeRequestSaslHandshakeResponseSASL ExchangeNormal OperationRequest (api_key, version, correlation_id)Response (correlation_id, data)

Request Processing Guarantee

Brokers process requests from a single connection in the order received and return responses in the same order. The broker processes one in-flight request per connection; clients may still pipeline requests in the TCP buffer.


Kafka ClientTransportProducer/Consumer APIRecord AccumulatorNetworkClientSelectorTLS (optional)SASL (optional)TCPApplicationKafka Broker
LayerResponsibility
ApplicationBusiness logic, data serialization
Client APIProducer/Consumer abstractions
NetworkClientConnection management, request dispatch
SelectorNon-blocking I/O, channel management
TransportTCP, TLS encryption, SASL authentication

KeyNameCategoryDescription
0ProduceCoreSend records to partitions
1FetchCoreRetrieve records from partitions
2ListOffsetsCoreQuery offset by timestamp
3MetadataCoreDiscover cluster topology
4-7Controller APIsInternalBroker coordination
8-9OffsetCommit/FetchConsumerOffset management
10-16Group APIsConsumerConsumer group protocol
17-18ApiVersions/SASLCoreVersion negotiation, auth
19-21Topic ManagementAdminCreate, delete, modify topics
22-28Transaction APIsTransactionExactly-once semantics
29-31ACL APIsAdminAuthorization management
32-51Config/AdminAdminCluster administration
52+KRaft/AdvancedInternalKRaft consensus, features (range evolves by version)

See individual API documentation for complete details.


Client/Broker Forward Compatibility (Kafka 4.0+ brokers)

Section titled “Client/Broker Forward Compatibility (Kafka 4.0+ brokers)”
Client VersionCompatibilityNotes
0.x, 1.x, 2.0❌ Not compatiblePre-0.10 protocols removed in Kafka 4.0 (KIP-896)
2.1 - 2.8⚠️ Partially compatibleSee Kafka 4.0 upgrade notes for client-specific limitations
3.x✅ Fully compatibleNo protocol-level limitations

Kafka 2.4 introduced "flexible versions" (KIP-482):

FeatureNon-FlexibleFlexible
StringsSTRING (INT16 length)COMPACT_STRING (VARINT)
ArraysARRAY (INT32 count)COMPACT_ARRAY (VARINT)
Tagged fields
Forward compatibilityLimitedImproved

RequirementLevelReference
Negotiate API versions before requestsshouldProtocol Messages
Track correlation IDs for response matchingmustProtocol Messages
Handle all error codes appropriatelymustProtocol Errors
Refresh metadata on leader change errorsshouldCore APIs
Use exponential backoff on retriesshouldProtocol Errors
Ignore unknown tagged fieldsmustProtocol Primitives

ApiVersions

Legacy clients may skip ApiVersions; brokers still support older request versions where available.

RequirementLevelReference
Process requests in order per connectionmustProtocol Messages
Echo correlation ID exactly in responsemustProtocol Messages
Support advertised API version rangesmustCore APIs
Respond to ApiVersions pre-authenticationmustCore APIs

CodeNameRetriableAction
0NONEN/ASuccess
6NOT_LEADER_OR_FOLLOWERRefresh metadata
7REQUEST_TIMED_OUTRetry with backoff
25UNKNOWN_MEMBER_IDRejoin group
27REBALANCE_IN_PROGRESSRejoin group
47INVALID_PRODUCER_EPOCHClose producer

See Protocol Errors for complete reference.

SettingDefaultPurpose
request.timeout.ms30000Request timeout
retry.backoff.ms100Retry backoff
metadata.max.age.ms300000Metadata refresh interval
max.in.flight.requests.per.connection5Request pipelining